I have a
template<class R>
class MyClass
{
public:
typedef std::function<void (const R)> ...;
};
Everything is ok until I try to use MyClass < void >.
In this case compiler expands typedef to
typedef std::function<void (void)> ...;
and does not want to cooperate.
If void is used as R parameter I want typedef to behave like:
typedef std::function<void ()> ...;
Since the class is pretty big I prefer type_traits and enable_if-like stuff instead of creating specialization for void.
As mentioned in comment, you may use an helper class:
template<class R>
struct MyClassHelper
{
using function_type = std::function<void (const R)>;
};
template <>
struct MyClassHelper<void>
{
using function_type = std::function<void ()>;
};
And then, in MyClass
template<class R>
class MyClass
{
public:
using function_type = typename MyClassHelper<R>::function_type;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With