Boost logo

Boost :

Subject: [boost] [parameter] type predicates vs. concepts
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-12-04 13:23:17

Hello all,

What's the difference between using a Boost.Parameter type predicate
and using a concept?

I think parameter type predicates are unary metafunctions used to
resolve the function call, concepts are asserted on the type after the
call has been resolved... Is there more? Can I always do with type
predicates what I can do with concepts? Is there ever a reason to
use/need both?

For example here has_equal_to is the type predicate while
DefautlConstructible is the concept. Could/should I have used
has_[...]_default_constructor in and_ the type predicate instead of
the DefaultConstructible concept?

#include <boost/parameter.hpp>
#include <boost/concept/requires.hpp>
#include <boost/concept_check.hpp>
#include <boost/type_traits/has_equal_to.hpp>
#include <iostream>

template< typename X >
BOOST_CONCEPT_REQUIRES( ((boost::DefaultConstructible<X>)), (bool) )
is_default_impl ( X const& x )
    return x == X();


    (required (x, *(boost::has_equal_to<tag::x::_>)) )
) {
    return is_default_impl(x);

struct no_equal {};

struct no_default { no_default(int) {} };
bool operator== ( no_default const&, no_default const& ) { return true; }

int main ( void )
    std::cout << is_default(123) << std::endl; // ok
    // parameter error: cannot resolve is_default() call
// std::cout << is_default(no_equal()) << std::endl;
    // concept error: no default constructor
// std::cout << is_default(no_default(1)) << std::endl;
    return 0;

Thanks a lot.

Boost list run by bdawes at, gregod at, cpdaniel at, john at