C++ concepts using one example

Hi Guys,


Could any one please send me the material links where i can find all the c++ concepts explained using single example of class?

i found lot of material but all of them are with different class examples per topic(polymorphism, inheritance etc)

Thanks in Advance.
The definition of "concept" is arbitrary. I guess you could list what you want to see.. But still, how do you expect that to be more useful than separate examples? If you want to see how they could be used, find yourself a project in sourceforge or etc.
In C++, the word "Concepts" has a specific meaning:
http://en.wikipedia.org/wiki/Concepts_%28C%2B%2B%29

You don't really need to worry about them, since they were not sufficiently realized to be included in C++11. The basic idea behind Concepts, AFAIU, is to apply some formal reasoning to templates so that they are less wild to play with.

For example, right now you can declare a template function like this:

1
2
3
4
5
6
7
8
9
template <typename ContainerType>
typename ContainerType::value_type
sum_elts( ContainerType& container )
  {
  typename ContainerType::value_type result = 0;
  for (typename ContainerType::size_type n = 0; n < container.size(); n++)
    result += container[ n ];
  return result;
  }

This kind of function never appears in code written by people who know better, but it is perfectly legal. The problem is that you can instanciate it with, say, a std::list. The compiler tries to compile it, gets confused, and barfs all over your terminal. You, bewildered, wonder what went wrong as you try to pick your way through the unfathomable chunks.

"Concepts" tries to fix this by modifying the template system to indicate what it can and cannot support, so that the compiler (and humans) can more directly reason about what is and is not acceptable.

Hope this helps.
Topic archived. No new replies allowed.