I have a template with C ++ templates
// Definition template <typename T> class MyCLass { public: typedef typename T::S MyS; // <-- This is a dependent type from the template one MyS operator()(const MyS& x); }; // Implementation template <typename T> MyCLass<T>::MyS MyClass<T>::operator()(const MyClass<T>::MyS& x) {...}
I want the overloaded operator operator()to behave differently when MySthere is one double.
operator()
MyS
double
I was thinking about specialization, but how to do this in this case, given that specialization should act on a type-dependent type? Thankyou
You can redirect work to some private overloaded function:
template <typename T> class MyCLass { public: typedef typename T::S MyS; MyS operator()(const MyS& x) { return operator_impl(x); } private: template<typename U> U operator_impl(const U& x); double operator_impl(double x); };
You can solve this problem by entering an additional default parameter:
template <typename T, typename Usual = typename T::S> class MyClass { ... };
Then you can specialize in double:
template <typename T> class MyClass<T, double> { ... }
Source: https://habr.com/ru/post/1502555/More articles:From Range Range to Range-Interval - oracleGet system time in milliseconds on android - javaРазделение элементов массива - javascriptHow to find out the actual refresh rate of a screen (not a rounded number) - windowsButton grid using UICollectionView? - iosInno Setup Scroll through the files and register each .NET dll - c #How to specialize a template member function in a template class in C ++? - c ++Div flickering when using CSS transform when hovering - htmlSphinx: include xlxs data in the first - restructuredtextConfiguring Inno How to determine if a file is a .NET assembly - .netAll Articles