|
Boost : |
Subject: Re: [boost] [concept] concept-based overloading (N2081)
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2010-05-27 14:04:27
Lorenzo Caminiti wrote:
> Hello all,
>
> How do I use Boost.ConceptCheck and/or Bosot.EnableIf to implement
> concept-based overloading (as discussed in N2081)?
You can't, at least with the current ConceptCheck design.
It would be possible to use SFINAE for expressions to do something
similar, but expressions need to be present in declarations for that,
and the concept definition system is based on the definition of a
function; it would need to use a more per-expression macro-heavy syntax
to support that kind of thing.
> For example, from N2081, the following functions are selected based on
> `Iter` matching one of the two specified concepts:
>
> template<InputIterator Iter> // proposed concept syntax (not C++)
> void advance(Iter& x, Iter::distance_type n) {
> while (n > 0) { ++x; --n; }
> }
>
> template<BidirectionalIterator Iter> // proposed concept syntax (not C++)
> void advance(Iter& x, Iter::distance_type n) {
> if (n > 0) while (n > 0) { ++x; --n; }
> else while (n < 0) { --x; ++n; }
> }
>
> How do I program this in C++ using Boost libraries?
That case is quite trivial, you can simply use the iterator_category, no
need to check whether the types fulfill special expressions.
> N2081 briefly mentions this can be done in C++ using SFINAE, etc.
Using SFINAE, you can deduce at compile-time things similar to auto
concepts, with a few caveats: access errors (private vs public) produce
hard errors.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk