Is there a way to make a constexpr
-Array of unsigned integers which fulfill some predicate given by the constexpr boolean function pred(std::size_t)
?
I tried a lot around, especially with the indices trick, just to find out that my data is too huge, such that it exceeds the recursive template instantiation limit of 256. I'll not be able to change this limit, if its possible to change it.
As asked in the comments, here is some pseudo code of what I would like to achieve:
template<std::size_t... Is>
struct Sequence{};
template<std::size_t N, std::size_t... Is>
struct SequenceGenerator : SequenceGenerator<N-1, N-1, Is...>
{}; //obviously here it gets too deep into recursion, as mentioned
template<std::size_t... Is>
struct SequenceGenerator<0, Is...> : Sequence<Is...>
{};
template<std::size_t N>
struct MyData
{
std::size_t values[N];
static constexpr std::size_t size()
{ return N; }
};
template<typename Lambda, std::size_t... Is>
constexpr MyData<sizeof...(Is)> MyGen(Sequence<Is...>, Lambda func)
{
if(func(Is)...)
return {{ Is... }};
else
return /*some not-invalidating but current element discarding thing*/
}
template<std::size_t N, typename Lambda>
constexpr Generator<N> MyGen(Lambda func)
{
return MyGen(SequenceGenerator<N>(), func);
}
constexpr bool pred(std::size_t i) noexcept
{
//some condition making up a "range"
return i < 360ULL && i > 2ULL;
}