I understand that the title of the question is confusing, so here is the example:
#include<array>
#include<optional>
#include<type_traits>
static constexpr std::optional<int> maybe_int() {
return {64};
}
struct s {
using type = std::conditional_t< maybe_int().has_value(), std::array<int, *maybe_int()>,float > ;
};
static_assert(std::is_same_v<s::type, std::array<int,64>>);
This code compiles fine but when I move maybe_int
inside struct compilation fails.
error: 'static constexpr std::optional<int> s::maybe_int()' called in a constant expression before its definition is complete
Note that I know the code works fine with free function, this is about readability. So I would like to move maybe_int
inside struct s.