
On Fri, May 28, 2010 at 12:02 PM, David Abrahams <dave@boostpro.com> wrote:
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.
Wow, I'll make sure to stay away from "not"/"or" concept constraints then.
(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.
Yes, I see. Thanks. -- Lorenzo