M
Marek Vondrak
Hello.
I have written the following program and am curious why it prints "1" "2".
What are the exact effects of explicitly providing function template
parameters at the call? Is the second assign() function really a
specialization of the first assign() or is it an assign() overload?
Thank you.
-- Marek
-- cut --
#include <iostream>
class O { };
class M { };
template <class Left, class Right>
class Plus { };
template <class Left, class Right, class Op>
int assign( Left & left, const Right & right, const Op & op )
{
return 1;
}
template <class Op>
int assign( M & left, const Plus<M, M> & right, const Op & op )
{
return 2;
}
int main()
{
M m;
std::cout << assign<M, Plus<M, M>, O>( m, Plus<M, M>(), O() ) <<
std::endl;
std::cout << assign( m, Plus<M, M>(), O() ) << std::endl;
}
-- cut --
I have written the following program and am curious why it prints "1" "2".
What are the exact effects of explicitly providing function template
parameters at the call? Is the second assign() function really a
specialization of the first assign() or is it an assign() overload?
Thank you.
-- Marek
-- cut --
#include <iostream>
class O { };
class M { };
template <class Left, class Right>
class Plus { };
template <class Left, class Right, class Op>
int assign( Left & left, const Right & right, const Op & op )
{
return 1;
}
template <class Op>
int assign( M & left, const Plus<M, M> & right, const Op & op )
{
return 2;
}
int main()
{
M m;
std::cout << assign<M, Plus<M, M>, O>( m, Plus<M, M>(), O() ) <<
std::endl;
std::cout << assign( m, Plus<M, M>(), O() ) << std::endl;
}
-- cut --