herolover
herolover

Reputation: 803

C++ template argument of template argument

Look at this code:

template<class T, class Compare>
void foo(const std::set<T, Compare> & bar)
{
    // here I need the comparative function BUT with another type
    // like this:
    if (Compare<float>()(...))
}

Something like this, but it doesn't work:

template<class T, class Compare>
void foo(const std::set<T, Compare<T>> & bar)
...

Is it possible?

Upvotes: 0

Views: 56

Answers (1)

Joseph Mansfield
Joseph Mansfield

Reputation: 110778

You want a template template parameter:

template<class T, template<class> class Compare>

Now the Compare template parameter is a template itself.

Upvotes: 4

Related Questions