C++ Logo


Advanced search

Re: [std-proposals] find_integral_constant

From: Sébastien Bini <sebastien.bini_at_[hidden]>
Date: Wed, 28 Sep 2022 15:59:50 +0200
On Wed, Sep 28, 2022 at 12:52 PM Marcin Jaczewski <
marcinjaczewski86_at_[hidden]> wrote:

> 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.

Received on 2022-09-28 14:00:03