Boost logo

Boost :

Subject: Re: [boost] Tick: Trait instrospection library for C++14
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2014-05-30 18:37:53


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 like the framework Eric has developed. The description is quite close
of what could be done at the language level.

What is the added value of your library respect to Eric work? E.g. next
follows the Addable concept checker

             struct Addable
             {
                 template<typename T, typename U>
                 using result_t = decltype(std::declval<T>() +
std::declval<U>());

                 template<typename T>
                 auto requires(T && t) -> decltype(
                     concepts::valid_expr(
                         t + t
                     ));

                 template<typename T, typename U>
                 auto requires(T && t, U && u) -> decltype(
                     concepts::valid_expr(
                         t + u
                     ));
             };

Best,
Vicente


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