Implement a template class definition for pair
template
class Pair
{
public:
Pair(const F& a, const S& b);
F get_first() const;
S get_second() const;private:
F first;
S second;
};
Implement the constructor for the template pair function (type F and S)
template
Pair::Pair(const F& a, const S& b)
{
first = a;
second = b;
}implement the get_first function for the template pair function (type F and S)
template
F Pair::get_first() const
{
return first;
}In this example CMP may be either a \_\_\_\_\_ or a \_\_\_\_\_\_\_\_
template
T max(const T& left, const T& right, CMP cmp)
{
if (cmp(left, right))
return right;
return left;
}Actual function or function object
what is the syntax for a template max function comparing employee objects alice & fred with functor CompareBySalary
max(alice, fred, CompareBySalary());
What is the error here? OrderedCollection a; OrderedCollection b; void f(OrderedCollection& c); f(a); f(b);
f(a); // Error - types don’t match
What is the header of a class OrderedCollection using the Less functor?
template >
class OrderedCollection
{
...
}What is the advantage of defining a make_pair function t as a template class?
We can execute a line like this auto pair1 = make_pair(5, “red”);
\_\_\_\_\_ template is a template function or class that can take a varying number of parameters
Variadic template
Variadic templates use varying parameters also known as _______ _____
parameter pack
Implement a print function that can take any number of inputs
void display(){}
template
void display(const Tfirst& param1, const Trest&…
params)
{std::cout <
void print(const Tvals& … parameters){
display(parameters…);}