Boost logo

Boost :

Subject: Re: [boost] [contract] toward N3351 concepts
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-09-27 13:21:34


On Thu, Sep 27, 2012 at 7:29 AM, Andrew Sutton <asutton.list_at_[hidden]> wrote:
> I'm glad to see this discussion.

I'm really glad to see N3351 author(s) part of it :) BTW, do you know
if a clang-based compiler supporting N3351 is actually being
implemented?

``
At the same time, we plan to build a compiler (based on Clang) for the
emerging language.
This prototype will support the full range features described in this
report. We hope to have an
initial version ready by early February, 2012.
''

Just to give a pick into a possible future of what Boost.Contract _could_ do:

// Header: boost/contract/std/concept/equality_comparable.hpp
namespace contract { namespace std {

CONTRACT_CONCEPT(
    concept (EqualityComparable) ( typename T ) (
        requires( (T) a, (T) b, (T) c ) (
            bool{a == b},
            bool{a != b},

            axiom( iff(a == b) eq(a, b) ),
            axiom(
                a == a,
                if(a == b) b == a,
                if(a == b and b == c) a == c
            ),
            axiom( iff(a != b) not(a == b) )
        )
    )
)

CONTRACT_CONCEPT(
    concept (EqualityComparable) ( typename T1, typename T2 ) (
        EqualityComparable<T1>,
        EuqalityComparable<T2>,
        (Common<T1, T2>),
        (EqualityComparable<CommonType<T1, T2> >),

        requires( (T1) a, (T2) b ) (
            bool{a == b},
            bool{b == a},
            bool{a != b},
            bool{b != a},

            axiom(
                typedef (CommonType<T1, T2>) C,

                iff(a == b) C{a} == C{b},
                iff(a != b) C{a} != C{b},
                iff(b == a) C{b} == C{a},
                iff(b != a) C{b} != C{a}
            )
        )
    )
)

} } // namespace

// Header: boost/contract/std/algorithm/find.hpp
namespace contract { namespace std {

// Not fully compatible.
CONTRACT_FUNCTION(
    template( typename I, typename T )
        requires( InputIterator<I>, (EqualityComparable<T, ValueType<I> >) )
    (I) (find) ( (I) first, (I) last, (T const&) value )
) {
    return std::find(first, last, value);
}

} } // namespace

BTW, why do we declare concepts like:

concept EqualityComparable< typename T > = ... // (1)

Instead of:

template< typename T >
concept EqualityComparable = ... // (2)

I personally prefer (2) because the template parameters are declared
with a syntax that is more consistent with the syntax used to declare
them in class/function templates. For similar reasons, I'd prefer {
... } instead of = ... for the concept definition part.

Thanks.
--Lorenzo


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