Subject: Re: [boost] [contract] concept error messages
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2012-10-08 12:45:36


On 08/10/12 12:16, Lorenzo Caminiti wrote:
<snip>
> 2) Another valid argument for requires is that the compiler will give
> the algorithm implementer an error if he/she uses the type in a way
> that doesn't model the concept (as Matt pointed out):
>
> template< typename T >
> requires EqualityComparable<T>
> bool equal ( T const& a, Tconst& b)
> {
> T x = a; // compiler error: T is not CopyConstructible, it's just
> EqualityComparable
> ...
> }
>
> Unfortunately, I don't think I can do this in a lib :( Can I? Does
> Boost.Generic provide such errors?

One way might be to form an archetype and instantiate the template with
it. I think Boost.Generic does (or at least aimed to) support the
creation of archetypes, but I doubt that it does this. I suspect such
an approach would be fraught with complications, but it might be workable.

John