Boost logo

Boost :

Subject: Re: [boost] [GSoC] [Boost.Hana] Formal review request
From: Roland Bock (rbock_at_[hidden])
Date: 2014-08-03 11:15:08


On 2014-08-03 15:56, pfultz2 wrote:
>> Could you post an example? Is the concept check done in the return type
>> as with enable_if?
> In C++11, we can use a default template parameter, rather than the return
> type, which is what the `CONCEPT_REQUIRES_` uses. So for example, we can
> write:
>
> template<typename... T,
> CONCEPT_REQUIRES_(BidirectionalIterator<T...>())>
> auto foo(T&&... xs)
> {
> ...
> }
>
> This works as long as all the varidiac template types are to be deduced by
> the
> compiler.

Thanks for the explanation. Good to know!

> For classes this won't work:
>
> // ERROR
> template<typename... T,
> CONCEPT_REQUIRES_(BidirectionalIterator<T...>())>
> struct foo
> {
> ...
> };
>
> Because you can't have a default template parameter after the varidiac
> template parameters in this context(you can when using speczializations).
>
> Of course, you can't use `CONCEPT_REQUIRES_` for class specialization. In my
> library, I do provide a `TICK_CLASS_REQUIRES` which can be used for class
> specializations. Note that since it relies on `enable_if` it won't resolve
> ambiguities like Concepts Lite will. For example:
>
> template<typename T>
> struct foo;
>
> template<typename T>
> struct foo<T,
> TICK_CLASS_REQUIRES(RandomAccessIterator&lt;T>())>
> {
> ...
> };
> // Here we have to add a check for `RandomAccessIterator` to avoid
> ambiguities
> template<typename T>
> struct foo<T,
> TICK_CLASS_REQUIRES(BidirectionalIterator&lt;T>() &&
> !RandomAccessIterator<T>())>
> {
> ...
> };
>
> Perhaps, there is a way to this using tag dispatching, I'm not sure.
>
>

Thanks and regards,

Roland


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