You can design your template in a smart way:
template < typename T, typename Duration = std::chrono::seconds, int duration_value = 30 > class MyClass {
And then you can instantiate your template as
MyClass < std::string, std::chrono::seconds, 30 > object;
Or, actually having these values as default values, simply
MyClass < std::string > object;
Edit:
Given the PaperBirdMaster request, you can restrict the Duration template type to only std::chrono::duration , as follows:
template <typename T> struct is_chrono_duration { static constexpr bool value = false; }; template <typename Rep, typename Period> struct is_chrono_duration<std::chrono::duration<Rep, Period>> { static constexpr bool value = true; }; template < typename T, typename Duration = std::chrono::seconds, int duration_value = 30 > class MyClass { static_assert(is_chrono_duration<Duration>::value, "duration must be a std::chrono::duration");
source share