LowerBound
is a member template function declared inside the class template MyClass
. It's similar to a function template but it is enclosed in a class (template).
The code can be simplified as
template <typename T>
class MyClass {
template <typename T1 = T, typename = std::enable_if_t<std::is_same<T1, int>{}>>
IndexValueType LowerBound(KeyType k) const {}
};
The first assignment T1 = T
means the default argument for the first template parameter is the same type of T
. If you are not explicitly specified, T1
will be T
. You could of course explicitly specify other types.
The second assignment here is an usage of std::enable_if
. Also pointed in the comments, it's a simple way to apply SFINAE. Here it will disable(ignore) templates when T1
is not the same as int
. Since the second parameter is only to restrict the first parameter and has no usage in the definition, its name is ignored.
MyClass<int> mc1; // T is int
mc1.LowerBound(...) // T1 is int, when not specified explicitly
mc1.LowerBound<std::int32_t>(...) // T1 is std::int32_t here
MyClass<double> mc2; // T is double
mc2.LowerBound<int>(...) // OK, T1 is int
mc2.LowerBound(...) // T1 is substitued with double here and will cause compile error since is not int