Boost's signals2 library defines a nice way to pass through alternate parameters for some of its extended functionality (via its Parameters library). When one of these alternate parameters is fairly commonplace in my code then I want to make a helper to simplify usage further; for example to specify an alternate mutex type I can do this:
namespace bs2 = boost::signals2;
template<typename Signature>
struct my_signal
{
typedef typename bs2::signal_type<Signature,
bs2::keywords::mutex_type<my_mutex> >::type type;
};
my_signal<void ()>::type some_signal;
Unfortunately by doing this I've also "lost" the ability to specify alternate values for the other signal parameters (such as combiner type), without going back to the verbose syntax or defining extra metafunctions such as my_signal_with_combiner or something (which seems silly). I don't think I can do that with a default template parameter value either since the default for Combiner requires breaking apart Signature to get the return type. (And ideally of course I'd like something that works for any of the other parameters, not just the combiner.)
So, the "real" question is: is there a (simple) way to define something like signal_type that behaves identically to it but has a different default value for one of the parameters? (Ideally, it shouldn't require changing if Boost.Signals2 adds more parameters in the future.)
(Also, no C++11 please. Still using an older compiler.)
I've worked out the following, which appears to do the trick. Still interested in improved answers, though:
One thing that has me a little puzzled is why the use of "combiner_type" in the constructor requires explicit scoping in the type declaration -- and then that it doesn't for the default parameter. (Removing either "typename" or "base_type::" here triggers the standard "default-int" error (which means "that doesn't look like a type I know"). Which is odd, since it's defined in the base class. I'm guessing it's some weird template-partial-instantiation thing.