Posts Tagged ‘variadic templates’
“function” is a useful library feature of Boost, TR1, and the upcoming C++ standard library. It’s basically a class template mimicing the behaviour of a function pointer. But it’s much more flexible because it applies to any “callable object” — function pointers and objects with overloaded function call operator. Also, the signatures don’t have to match perfectly as long as the parameters and return values are implicitly convertible. I’m going to show you how this library feature can be implemented with C++0x features — including variadic templates and rvalue references. But before going into any details let me give an example of how code that uses this “function” library might look like. In case you’re already familiar with this library feature you can skip the following piece of code and paragraph of text.