I have some class that I would like to be initialized at compile time by an initializer list that needs some level of validation.
I first tried static_assert but that wouldn't compile with the error "non-constant condition for static assertion"
What is the best way to causing a build error with this?
class foo {
public:
constexpr foo(std::initializer_list<bar> items) {
for(auto &&i: items) {
if(i == 12) // example validation logic
// fail the build
}
}
}
constexpr foo foo_list({0,1,2,3,4,5});// should succeed
constexpr foo foo_list_bad({0,1,12,4,68});// should fail to build
std::index_sequenceinstead ofinitializer_list?