The article describes a method of grouping types in the C ++ language, implemented through the template IGroup class. Reception of grouping types allows you to specify several types for the object. For example, you can specify two object interfaces.
In general, this technique could be a language construct, but I have
not seen such a construct
in any PL (I already explained in the comments what we are talking about about Generics and Boost, and even about STL, thanks for the discussion). Because it was interesting to try to implement it in C ++.

')
Suppose you have several interfaces:
1) Flyable
2) Quackable
3) Duck
Some of the types will implement all of these interfaces at once, some will only implement part of the interfaces. How to indicate that a certain method works only with objects that can fly (Flyable) and quack (Quackable)?
The problem is described in more detail in the book Design Patterns (Bates B., Sierra C., Freeman E., Freeman E.). Link to the
book itself. The publisher’s site has a necessary
fragment of a book with a detailed description of the interface separation problem.
We offer you the following template with three specializations for a different number of parameters:

The use of the pattern is assumed as follows:
1) To implement the interface group:

2) To enumerate the required interfaces in the parameters of the methods:

Thus, the type of the parameter explicitly lists the interfaces that the object must implement.
The IGroup template class described above has one major drawback - the order of the types enum is significant. To eliminate this feature, you will need to list factorial times as many types in the IGroup inheritance. That is, indicate not all possible
combinations of types, in the quantity
(N-1) of
N , but their various
placements . The locations
(N-1) of objects from the
N possible to
(N-1)! times more than combinations.
Sample code for three parameters:

The full code of the example is given here:
http://codepad.org/ONI6uXjIOf course, you should not write the code for the IGroup with the 5th and 6th parameters manually - you need a script to generate this thousand-line code. For full use, there is not enough work with smartpoints. I will try the other day, but it seems to me that there will be no problems when casting “smart” pointers.
UPDATE1:As it was rightly noted by comrades
burdakovd and
tangro in comments
1 and
2 , in Java and .NET support for this mechanism is in Generics. Link to the description of
Java Generics and
.NET Generics .
UPDATE2:The user
susl rightly noted in his
comments that the Boost library has a
Boost Concept Check mechanism, for which a special thanks to him.
UPDATE3:Comrade
Balthasar clarified the situation about the concepts in the new C ++ 0x standard, or rather, about their absence. And he brought links to the
slides of the Boost Concept Check presentation . For which he thanks more!