Demonstrate problem. There is a class that takes an object type and the type of container for this object.
So you can not write, you should use the template template parameters, to indicate that the
Container itself is structured.Correctly write:
Use this:
At the first use we get a compilation error. We have forgotten that std :: vector takes two parameters, one of which is usually the default. Well, we can rewrite:
There are two obvious problems:
- We must look into the implementation of std :: vector, find out what type allocator used by default, and then use it.
- We wrote a template will not work if the container is more than one template parameter default.
I would like to avoid explicit default type and complex syntax template template parameters. Comes to the aid technique based on the use of placeholders boost :: mpl, are used to create a lambda metafunctions. Externally, the only difference is that you need to pass to our template is not the template container and container instantiated template placeholders, ie instead
write
To instantiate instantiated placeholder container necessary type using boost :: mpl :: apply:
Using this trick in real programming help simplify some of your intricate patterns.
No comments:
Post a Comment