views:

349

answers:

2
+8  Q: 

What are concepts?

I've heard all this new (on /.) about C++0x not having concepts anymore, but I have no idea what they are? Can someone explain to me?

+5  A: 

Here is an article that I think would help:

http://www.devx.com/SpecialReports/Article/38864

The decision to remove them has been discussed several times here at SO as well. These might prove interesting:

c0x No longer has concepts

Concepts compared to Interfaces

Hypothetical discussion of concepts

EBGreen
+13  A: 

Concepts are a generic programming feature which allow someone writing templated code to specify requirements which the type parameters need to meet.

For example, some collection types need for the type parameter for the collection to define the < operator. So the programmer might define a concept called LessThanComparable which tells the compiler that the type parameter to the templated class needs to have operator< defined. If the template user then tries to instantiate the template using a type that does not have the LessThanComparable concept (i.e. does not have an operator< function) the compiler can emit a simple error message rather than the torrent of error messages associated with templated code. The compiler may also be able to take advantage of the extra information provided by concepts to generate more efficient code.

This is somewhot of an oversimplication, but I think it gives you the general idea behind concepts.

If you want to try out some of the capabilities of concepts, take a look at the Boost.Concept Check library. I don't think it provides the full range of capabilities that were going to be in the standard, but it's a good place to start.

You may also want to look at ConceptC++, there's a good definition of concepts there.

Ferruccio
Huh, that is almost exactly what EBGreen's link said! Weird coincidence, huh?
Hooked
Not really. I read that article when it was first published almost a year ago. I do have the ability to retain information :-)
Ferruccio
great answer. this was one of the questions about C++ I had been afraid to ask
chester89