|
Boost : |
Subject: Re: [boost] Tick: Trait instrospection and concepts library now for C++11
From: pfultz2 (pfultz2_at_[hidden])
Date: 2014-06-08 06:02:06
> Have you read the Concept-Based Overloadingin Eric's blog [1]? Eric uses
> a dispatching schema on which the Concept definition is the tag
> dispatcher.
Yes, I have, however, tag dispatching doesn't work with
specialization(neither
does concept-based overloading, apparently). After thinking about it more, a
simpler way is to just use conditional overloading instead, which would work
something like this:
struct advance1
{
template<class Iterator,
TICK_REQUIRES(is_random_access_iterator<Iterator>())>
void operator()(Iterator& it, int n) const
{
it += n;
}
};
struct advance2
{
template<class Iterator,
TICK_REQUIRES(is_input_iterator<Iterator>())>
void operator()(Iterator& it, int n) const
{
while (n--) ++it;
}
};
tick::conditional<advance1, advance2> advance = {};
The order the functions are placed matter, think of it like this pseudo-
syntax:
template<class Iterator>
void advance(Iterator& it, int n) if
(is_random_access_iterator<Iterator>())
{
it += n;
}
else if (is_input_iterator<Iterator>())
{
while (n--) ++it;
}
Perhaps, some macros could help to reduce the boilerplate.
> This is not a good idea. The default will be checked independently of
> whether increment is used or not, isn't it?
It gets checked when increment gets called(at instantiation). If
`is_incrementable` is false, it will cause substitution failure.
Paul
-- View this message in context: http://boost.2283326.n4.nabble.com/Tick-Trait-instrospection-and-concepts-library-now-for-C-11-tp4663438p4663713.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