Hello Everyone,
For those interested. I added support for tag dispatching in the Tick. The
reason it wasn't added earlier was concern over specialization. So now as a
simple example, the `advance` function could be implemented like this:
TICK_TRAIT(is_incrementable)
{
template<class T>
auto requires_(T&& x) -> tick::valid<
decltype(x++),
decltype(++x)
>;
};
TICK_TRAIT(is_decrementable, is_incrementable<_>)
{
template<class T>
auto requires_(T&& x) -> tick::valid<
decltype(x--),
decltype(--x)
>;
};
TICK_TRAIT(is_advanceable, is_decrementable<_>)
{
template
auto requires_(T&& x, Number n) -> tick::valid<
decltype(x += n)
>;
};
template<class Iterator>
void advance_impl(Iterator& it, int n, tick::tag)
{
it += n;
}
template<class Iterator>
void advance_impl(Iterator& it, int n, tick::tag)
{
if (n > 0) while (n--) ++it;
else
{
n *= -1;
while (n--) --it;
}
}
template<class Iterator>
void advance_impl(Iterator& it, int n, tick::tag)
{
while (n--) ++it;
}
template<class Iterator>
void advance(Iterator& it, int n)
{
advance_impl(it, n,
tick::most_refined>());
}
Now, specialization is still supported in a sane way. As an example, say
there
was an iterator called `foo_iterator` that fulfilled the type requirements
for
`is_incrementable`, `is_decrementable`, and `is_advanceable`, but it had an
incorrect `+=` operator on it(perhaps it crahsed at runtime). So
`is_advanceable` can be specialized to prevent this problem:
template<>
struct is_advanceable
: std::false_type
{};
Even though it is specialized to false, it can still dispatch to
`tag` and `tag` tags. You can read more
about it here:
http://pfultz2.github.io/Tick/doc/html/tag/
Any feedback is appreciated. Thanks,
Paul Fultz II
--
View this message in context: http://boost.2283326.n4.nabble.com/C-Concept-based-tag-dispatching-using-the...
Sent from the Boost - Dev mailing list archive at Nabble.com.