|
Boost : |
Subject: Re: [boost] [GSoC] [Boost.Hana] Formal review request
From: pfultz2 (pfultz2_at_[hidden])
Date: 2014-08-03 09:56:55
> 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. 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<T>())>
{
...
};
// Here we have to add a check for `RandomAccessIterator` to avoid
ambiguities
template<typename T>
struct foo<T,
TICK_CLASS_REQUIRES(BidirectionalIterator<T>() &&
!RandomAccessIterator<T>())>
{
...
};
Perhaps, there is a way to this using tag dispatching, I'm not sure.
-- View this message in context: http://boost.2283326.n4.nabble.com/Re-GSoC-Boost-Hana-Formal-review-request-tp4665622p4665967.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