Question

template <type1 _Type1, type2 _Comparator=...  >

I am trying to implement a class. the first parameter can be a string, a set or a list. The second parameter is a comparator. I would like to use the comparator < as a default parameter for type2.

I did not find the correct syntax for this, may you help me please?

EDIT: the answer given was good but not in my case. I realized that I was looking for:

template <typename _Type, typename _Comparator=less<typename _Type::value_type> >

and not

template< class Type1, class Comparator = std::less<Type1> >

Because I need to compare elements which are part of the _Type.

Was it helpful?

Solution

I think this may be what you're after:

template< class Type1, class Comparator = std::less<Type1> >

Note that names starting with underscore followed by uppercase are reserved to the implementation.

std::less is declared by the <functional> header.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top