Callbacks in C++

automatically detect types


You have created a template class that is just plain unwieldy to use. Either the template has so many arguments that type specification are too long, or the template is typically used with such complex types that the specification are difficult to write and read. Examples of complex types are templates with lots of arguments, function pointers, member function pointers, etc.




Create a template function called make_TEMPLATENAME, substituting something appropriate for TEMPLATE NAME, that returns an instance of your template class either by name or by value.

forces resolved:

design rationale:

The types used for instantiating template functions are based on the types of the arguments passed to the function and not on explicit specification of those types. This feature can be taken advantage of to reduce the complexity of instantiating complex templates. Many types, such as pointers to functions and member functions are much easier to get an instance of than they are to declare the type. If you are creating a template where after you specify all of the types, you will immediately specify all of the arguments for initializing those types, using the templated make function will always reduce the amount of work the user has to do.

In cases where some of the types are not being passed as arguments for initialization, passing arguments that are ignored such as the number 0 cast to be a pointer to the appropriate type can help fill in the gaps.

[View/Add Comments]

Callbacks in C++
Copyright © 1996-2000 Paul Jakubik
Created: 26 July 1996. Last update: 26 November 2000.