Did VHDL-2008 ever add a way to do this?
constant k : integer := 5 when BOOLEAN_GENERIC else 8;
I.e, to do the Verilog ?: operator? Having to write a function to
make this work is awkward and verbose.
The awkward and verbose function is at the end of the post. However, once you've taken the trouble to write (or copy/paste) this code, you should putit into a package of 'useful, general purpose functions that you can then use whenever you need them' and you can use those functions without ever having to look at that code again.
Effectively, you extended the language in your own preferred direction and there is nothing negative about that. You won't even need to wonder if some version of the language now supports what you want or, just as importantly, wonder if the tool you're using supports that new construct. Plus, whatif down the road, you'd like to have a function that works with std_logic conditions (or input parameters), you can simply copy/paste the code, modify two lines and be ready to go thanks to VHDL's function overloading. The ability to basically customize the language is a 'good thing', waiting for the standards folks and the tool supplier folks to get onboard...not so mucah a 'good thing'.
Using the code that you'll write once and then (probably) never have to look at again is as simple as using any std_logic or numeric_std or other library function that you already take for granted. Now you'll have the start of your own library of functions that you can also take for granted.
library work.my_pkg_of_vhdl_stuff.all;
....
constant k: integer := sel(BOOLEAN_GENERIC, 5, 8);
or ...
constant k: integer := sel(Cond => BOOLEAN_GENERIC, If_True => 5, If_False => 8);
Kevin Jennings
---*** START CODE ***---
----------------------------------------------------------------
-- Functions to select one or the other based on a boolean (or
-- std_ulogic or std_logic) input.
-- Analogous to the C statement x = Cond ? a : b
----------------------------------------------------------------
function sel(Cond: BOOLEAN; If_True, If_False: integer) return integer is
begin
if (Cond = TRUE) then
return(If_True);
else
return(If_False);
end if;
end function sel;
---*** END CODE ***---