C++ concepts

Justin Johansson no at spam.com
Tue Feb 16 03:03:24 PST 2010


This evening I was reading an article comparing Haskell and C++ and it
gave some example C++ code using a keyword I had never heard of, namely,
"concept".  I'm thinking to myself, "this ain't C++" so
to be sure to be sure to be sure
I checked out Wikipedia and soon discovered that the C++ "concept"
keyword was to be something new in C++0x only to be pulled out just
about as fast as it was put in.

Here's the Wikipedia link:

http://en.wikipedia.org/wiki/Concepts_(C%2B%2B)

and a snippet from that link:

++ template classes and functions necessarily impose restrictions on the 
types that they take. For instance, the standard library containers 
require that the contained types be assignable. Unlike the dynamic 
polymorphism that class inheritance hierarchies exhibit, where a 
function that accepts an object of type Foo& can be passed any subtype 
of Foo, any class can be supplied as a template parameter so long as it 
supports all of the operations that users of actual instantiations upon 
that type use. In the case of the function, the requirement an argument 
must meet is clear (being a subtype of Foo), but in the case of a 
template the interface an object must meet is implicit in the 
implementation of that template. Concepts provide a mechanism for 
codifying the interface that a template parameter must meet. (See also: 
type class).

Anyway, fwiw, and being a sharing and caring kind of person :-),
I was wondering if any of the concepts regarding C++0x's "concept"
keyword would be of interest to D people, especially those of you
who have an interest in metaprogramming. Hey, maybe it's something
already coming to a D2 screen near you, I don't know.

Cheers
Justin Johansson



More information about the Digitalmars-d mailing list