Boost logo

Boost :

Subject: [boost] Boost iterators are not SFINAE-friendly
From: pfultz2 (pfultz2_at_[hidden])
Date: 2014-05-17 18:21:21


Boost iterators aren't SFINAE-friendly. This is a problem when building
traits
that detect certain behavior. Heres a simple example:

    #include <vector>
    #include <type_traits>
    #include <boost/iterator/filter_iterator.hpp>

    template<class>
    struct holder
    {
        typedef void type;
    };

    template<class Iterator, class=void>
    struct is_advanceable
    : std::false_type
    {};

    template<class Iterator>
    struct is_advanceable<Iterator, typename holder&lt;
        decltype(std::declval&lt;Iterator>() += std::declval<int>())
>::type>
    : std::true_type
    {};

    static_assert(is_advanceable<std::vector&lt;int>::iterator>::value,
"This will pass");

    struct predicate
    {
        template<class T>
        bool operator()(T&&) const;
    };

    static_assert(not is_advanceable<boost::filter_iterator&lt;predicate,
std::vector&lt;int>::iterator>>::value, "This won't pass");

Although, it doesn't always lead to a compile error(rather than subtitution
failure), it does lead some very erroneous errors.

Thanks,
Paul

--
View this message in context: http://boost.2283326.n4.nabble.com/Boost-iterators-are-not-SFINAE-friendly-tp4662474.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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