Boost logo

Boost :

Subject: Re: [boost] [concept] "not" and "or" concept constraints (N2081)
From: David Abrahams (dave_at_[hidden])
Date: 2010-05-28 12:02:16


At Fri, 28 May 2010 11:31:09 -0400,
Lorenzo Caminiti wrote:
>
> Hello all,
>
> How can I use Boost.ConceptCheck to implement "not" and "or" concept
> constraints as they are defined in N2081?

A. You can't, not with Boost.ConceptCheck.

B. Those are a really bad idea anyway. It's been proven
   mathematically that the use of “or” constraints would lead to a
   combinatorial explosion at typechecking time.

> (If this is obvious from the documentation, please just point me to the link.)
>
> For example, how can I program the following code from N2081 using
> Boost.ConceptCheck:
>
> // "not" `!` concept constraint for some concept C (not C++ code).
> template<Regular T> where !C<T> void f(T x) { ... }
>
> // "or" `||` concept constraint (not C++ code).
> template<Regular T> where Integral<T> || Floating<T> T cos(T x) { ... }
>
> If I understand it right, I can program the "and" concept constraints
> in Boost.ConceptCheck just by specifying multiple concepts as in:
>
> // "and" `&&` concept constraint.
> template<typename T>
> BOOST_CONCEPT_REQUIRES( ((boost::Integral<T>)) ((boost::
> Arithmetic<T>)),
> T) f(T x) { ... }
>
> But how do I use BOOST_CONCEPT_REQUIRES(), etc to program "not" and
> "or" concept constraints?

Boost.ConceptCheck generates errors aggressively, which means you
can't use BOOST_CONCEPT_REQUIRES in an overloading context where one
overload's requirements might not be satisfied. For this use case you
need to use type traits, MPL, and enable_if.

-- 
Dave Abrahams           Meet me at BoostCon: http://www.boostcon.com
BoostPro Computing
http://www.boostpro.com

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