Boost logo

Boost Users :

Subject: Re: [Boost-users] [Concepts & EnableIf] Is void special?
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2012-03-28 11:24:50


On Wed, 28 Mar 2012, Robert Jones wrote:

> Hi All
>
> Ok, I should probably have started this thread with this self contained code example.
>
> What's wrong with this?
>
>
> #include <vector>
> #include <boost/concept/requires.hpp>
> #include <boost/range/concepts.hpp>
> #include <boost/utility/enable_if.hpp>
> #include <boost/type_traits/is_same.hpp>
>
> template <typename T>
>     BOOST_CONCEPT_REQUIRES(
>             (( boost::SinglePassRangeConcept<T> )),
> //             ( void ))
>             ( typename boost::enable_if<boost::is_same<typename boost::range_value<T>::type, int>, void>::type ))
>     f( const T & ) { }
>
> int main( )
> {
>     std::vector<int> v;
>     f( v );
> }
>
> g++    -c -o enable_if.o enable_if.cpp
> enable_if.cpp: In function ‘int main()’:
> enable_if.cpp:17: error: no matching function for call to ‘f(std::vector<int, std::allocator<int> >&)’
>
> If I comment out the enable_if line and comment in the void line it's fine.

It looks like the trick is to put the enable_if outside the
BOOST_CONCEPT_REQUIRES, as in:

template <typename T>
typename enable_if<
            condition,
            BOOST_CONCEPT_REQUIRES(concept, (void))>::type

Paragraph 4 of [dcl.fct] (in the latest draft) seems to say that the
SFINAE error you are getting is required: only the specific type void,
written in a non-dependent way, counts as a valid function parameter type.

-- Jeremiah Willcock


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net