Add two callbacks, one with correct index and other for "default"
case, then the user can handle it anyway he wants:
throw, return default value, terminate or mark it as unreachable code.
I am not so sure, because then most users will have to supply a no-op lambda if they don't care about the error case.
I think of the following two signatures:
// Returns whether the integral constant was found
template <std::size_t N, class Functor>
bool find_integral_constant(std::size_t index, Functor&& func);
// Throws std::out_of_range if the integral constant was not found
template <std::size_t N, class Functor>
decltype(auto) find_integral_constant(std::size_t index, Functor&& func);
I prefer the second one as we can retrieve the return value from the functor. Other functions in the STL throw exceptions in case of errors, I think it's safe to do it in that case as well.