Boost logo

Boost :

Subject: Re: [boost] dramatically improved template error messages (was: C++11 decltype/SFINAE puzzler)
From: Ahmed Charles (acharles_at_[hidden])
Date: 2012-08-14 20:02:08


> I tinkered for a little bit, and couldn't get what I wanted. The
> problem, from the perspective of general concept checking, is that I
> want compilation to fail when a substitution failure would happen. For
> example:
>
> template <typename I, typename T>
> I find(I first, I last, const T& value) {
> static_assert (Input_iterator<I>(), "");
> while (first != last && *first != value) ++first;
> }
This technique comes closer, but you still get errors messages for a missing copy constructor... I think.
template <typename I, typename T>
  I find_impl(I first, I last, const T& value, true_type) {
    while (first != last && *first != value) ++first;}
template <typename I, typename T>
I find_impl(I first, I last, const T& value, false_type) {
    return first;}
template <typename I, typename T>
I find(I first, I last, const T& value) { static_assert (Input_iterator<I>(), "");
    return find_impl(first, last, value, std::integral_constant<bool, Input_iterator<I>()>());
}


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