Boost logo

Boost :

Subject: Re: [boost] Tick: Trait instrospection library for C++14
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2014-06-02 09:35:39


Le 22/05/14 18:23, paul Fultz a écrit :

> Hi,
>
> I developed a trait introspection library for C++14 based on Eric Niebler's
> concept checking, here:
>
> https://github.com/pfultz2/Tick
>
> So you can build a simple `is_incrementable` trait like this:
>
> TICK_TRAIT(is_incrementable)
> {
> template<class T>
> auto requires(T&& x) -> TICK_VALID(
> x++,
> ++x
> );
> };
>
> Then use it like this:
>
> static_assert(is_incrementable<T>(), "Not incrementable");
>
> Also, you can validate the return of an expressions like this:
>
> TICK_TRAIT(is_equality_comparable)
> {
> template<class T, class U>
> auto requires(T&& x, U&& y) -> TICK_VALID(
> returns<bool>(x == y),
> returns<bool>(x != y)
> );
> };
>
> You can also match against another trait using placeholder expressions:
>
> TICK_TRAIT(is_incrementable)
> {
> template<class T>
> auto requires(T&& x) -> TICK_VALID(
> return<std::is_integral<_>>(x++),
> return<std::is_integral<_>>(++x)
> );
> };
>
> Any feedback would be appreciated. Also, I don't knw if there would be any
> interest in incorporating this into boost.
>

I recommend that you do not use identifiers 'concept' or 'requires'. They
are likely to become keywords in C++17. See
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4040.pdf. If
added, this will break your code and negatively surprise your users. Worse,
if your library becomes popular, it may prevent the addition of the
keywords, and C++ will have to resort to uglier names like "concept_def"
and "concept_requires".

Regards,
7rzej


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