T
Tricky
Guest
So Im messing arround with VHDL - Ive created a package that contains a linked list with a generic type.
There is one issue I cant seem to work out in my head - is it possible create a generic that defaults to the initial value of the generic type? At the moment, when the there are no values in the list, the "get_item" function will return the default value of the generic type - so I want to give the package a "null_value" generic, so it is easy to detect a null return (ie an empty list).
package ll_test_pkg is
generic (
type data_t;
null_value : data_t := <what goes here?>;
);
type link_list_t is protected
procedure add_item( i : data_t );
impure function get_item return data_t;
end protected link_list_t;
end package ll_test_pkg;
I could just force the user to explicitly specify the null_value when instantiating the package, but it would be nicer (for me) if it defaulted to the initial value of data_t.
I could also make the get_item a procedure that outputs a data_t and an empty_list boolean, but I wondered if the above was possible?
There is one issue I cant seem to work out in my head - is it possible create a generic that defaults to the initial value of the generic type? At the moment, when the there are no values in the list, the "get_item" function will return the default value of the generic type - so I want to give the package a "null_value" generic, so it is easy to detect a null return (ie an empty list).
package ll_test_pkg is
generic (
type data_t;
null_value : data_t := <what goes here?>;
);
type link_list_t is protected
procedure add_item( i : data_t );
impure function get_item return data_t;
end protected link_list_t;
end package ll_test_pkg;
I could just force the user to explicitly specify the null_value when instantiating the package, but it would be nicer (for me) if it defaulted to the initial value of data_t.
I could also make the get_item a procedure that outputs a data_t and an empty_list boolean, but I wondered if the above was possible?