Boost logo

Boost :

Subject: Re: [boost] dramatically improved template error messages
From: Andrew Sutton (asutton.list_at_[hidden])
Date: 2012-08-16 09:44:09


> To avoid redundant errors, you must dispatch to an empty implementation
> on concept check failure:
>
> template <typename I, typename T>
> I find_impl(std::true_type, I first, I last, const T& value) {
> while (first != last && *first != value) ++first;
> }
>
> template <typename I, typename T>
> I find_impl(std::false_type, I first, I last, const T& value) {
> static_assert (Input_iterator<I>(), "");
> }
>
> template <typename I, typename T>
> I find(I first, I last, const T& value) {
> find_impl(Input_iterator<I>(), first, last, value);
> }
>
> Not if you use the trick above.

Interesting... That looks like it will work. Do you still need the
sfinae_error class to get shallow errors? I'm guessing not in these
cases.

> You only have the guard the calls that add constraints. Other calls will
> simply propagate sfinae_error and don't need to be guarded. (In my
> example, S2 doesn't need to guard the call to S1, but S1 must guard S0
> because it adds an Addable constraint.) Also, you can guard your
> function object once by defining it with try_call_wrapper, so it doesn't
> need to be guarded everywhere.
>
> Just apply more force. :-)

Indeed :)

Side note: sfinae_error is a bad name in a worse way than how "PIN
number" is redundant. It's not an error, but it is.
substitution_failure or subst_failure might be better choices.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk