Is there a method to decide whether something can be constexpr evaluated, and use the result as a constexpr boolean? My simplified use case is as follows:
template <typename base>
class derived
{
template<size_t size>
void do_stuff() { (...) }
void do_stuff(size_t size) { (...) }
public:
void execute()
{
if constexpr(is_constexpr(base::get_data())
{
do_stuff<base::get_data()>();
}
else
{
do_stuff(base::get_data());
}
}
};
My target is C++2a.
I found the following reddit thread, but I'm not a big fan of the macros. https://www.reddit.com/r/cpp/comments/7c208c/is_constexpr_a_macro_that_check_if_an_expression/
if constexpr
will only be evaluated if the expression in theif constexpr
is true at compile time. Is that what you are looking for? – Sternstd::is_constant_evaluated
? – Severancedo_stuff
that it can run at compile time or runtime, but itself should not beconstexpr
? Wouldn't it make more sense to just make it aconstexpr
function, and pass it the value ofget_data
as a parameter? – Epigone