
On Wed, Oct 10, 2012 at 4:51 AM, Andrzej Krzemienski <akrzemi1@gmail.com>wrote:
Even if you decide to go with pseudo-signatures, one novel thing from N3351 is worth adapting: treating every concept as a predicate, so that the programmer can check himself whether a certain set of types models the concept:
static_assert( ForwardIterator<int*>, "ouch" );
and so that you can combine concept requirements with any boolean meta-function:
template <class T> requires Copyable<T> && sizeof(T) < 8 ...
The functionality of retrieving a boolean value is supported in Boost.Generic, but you can't just use the concept directly as a value/MPL-style integral constant because accessing the concept as, for instance, Copyable<T> has to access the concept map. Making it an MPL integral constant type would conflict. The way you do it in Boost.Generic is any of a number of ways. First, if you want a boolean value you can use the macros BOOST_GENERIC_CONCEPT_IS_MODELED_BY and BOOST_GENERIC_CONCEPT_IS_MODELED_BY_C. If you want to assert, which is generally more common, you can #include <boost/generic/assert.hpp> and do any of the following: // Generates a static_assert, alerting the user if the concept is not modeled and all of the individual reasons why it's not. BOOST_GENERIC_ASSERT( YourConcept< T > ); // Generates a static_assert, alerting the user if the concept is not modeled, giving a user-provided error message. Boost_GENERIC_ASSERT_MSG( YourConcepts, "Your message." ); // Generates a static_assert, alerting the user if the concept is modeled. BOOST_GENERIC_ASSERT_NOT( YourConcept< T > ); // Generates a static_assert, alerting the user if the concept is modeled, giving a user-provided error message. BOOST_GENERIC_ASSERT_NOT_MSG( YourConcept< T >, "Your message." ); If you look through the Boost.Generic std_concept/concepts and std_concept/support_concepts tests in the sandbox you can see examples. I'm working on detailed documentation right now while I update some other functionality in the library, but there's a ton of stuff to do at the moment. -- -Matt Calabrese