Boost logo

Boost :

Subject: Re: [boost] Tick: Trait instrospection and concepts library now for C++11
From: pfultz2 (pfultz2_at_[hidden])
Date: 2014-06-07 01:18:35


> Does your library define just traits or try to emulate Concept Lite?

I'm not quite sure what you are asking. The library doesn't do everything
that
Concepts Lite does. It lets you define concept-like predicates(commonly
called a
type trait in C++) in a similiar manner as Concepts Lite does. It does do
template constraints as well, but this is just done using `enable_if`. Also,
it
won't resolve ambiguity between overloads like Concepts Lite does. However,
I am
thinking about implementing a mechanism for this. Perhaps something like
this:

    struct advance1
    {
        template<class Iterator>
        TICK_OVERLOAD_REQUIRES(is_random_access_iterator<Iterator>);

        template<class Iterator>
        void operator()(Iterator& it, int n) const
        {
            it += n;
        }

    };

    struct advance2
    {
        template<class Iterator>
        TICK_OVERLOAD_REQUIRES(is_input_iterator<Iterator>);

        template<class Iterator>
        void operator()(Iterator& it, int n) const
        {
            while (n--) ++it;
        }

    };

    tick::overload<advance1, advance2> advance = {};

However, this is fairly verbose even with the help of macros. It just might
be
easier to add some `not`s to the requires clause.

Now, non-template members can be disabled, but they need to be made
templated,
like this:

    template<class Base>
    struct A : Base
    {
        template<class Self=A, TICK_REQUIRES(is_incrementable<Self>())
        void increment()
        {
            ++(*this);
        }
    };

However, the library cannot be used with special members(such as copy
constructors, move constructors, and assignment operators). This is a
limitation
of the language, since these special members cannont ever be templates.
There
might be a way to workaround the issue using universal references. I haven't
really looked into it.

Thanks,
Paul

--
View this message in context: http://boost.2283326.n4.nabble.com/Tick-Trait-instrospection-and-concepts-library-now-for-C-11-tp4663438p4663647.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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