Re: Emulating concept based overloading
on Thu Aug 28 2008, Mathias Gaunard <loufoque-AT-gmail.com> wrote:
On 24 ao??t, 01:58, Kaba <n...@here.com> wrote:
The former is an unrestricted template, while the latter matches only
specific classes. However, the classes can contain any type that models
the concepts (View2 and ConstView2) and they itself model the same
concepts. Thus this kind of emulates concept based overloading.
Concepts are structural subtyping and are perfectly implicit.
Actually, that's not quite true. Don't forget that concepts have
semantic requirements that can't be deduced by the compiler. There many
input iterators that look, structurally, exactly like forward
iterators. If you don't do something explicit to distinguish them, it
has severe consequences. Try
std::vector<int>(b, e);
on your favorite standard library where b and e are mis-labeled input
iterators, and you'll see why. Expect a crash or worse. That's part of
why concepts in C++0x are not "auto" by default. From my P.O.V., having
to explicitly state concept conformance is the norm.
I fail to see how your approach does it. It is nothing but an explicit
subtyping technique.
I haven't looked at the code, but IMO there are two things required to
make it an interesting technique from a Generic Programming point of view:
* it would have to be *non-intrusive*, so you could establish
conformance of a type T to a concept X without altering T or X.
* it would have to be able to establish conformance of all instances of
a template to a given concept, i.e., "all vector<T> instances model
RandomAccessContainer."
--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]