#include <iostream>
struct Cls{double dval = 0;};
template<typename T>
void foo(T&& Obj) {
//..... use Obj
}
void foo(const Cls& Obj) {
//..... use Obj.dval
}
//void foo(Cls Obj) {
// //..... use Obj.dval
//}
int main()
{
Cls Obj;
const Cls cv_Obj;
foo(Obj); //case 1
foo(Cls{}); //case 2
foo(cv_Obj); //case 3
foo(10.10);
}
template specialization for Cls
fails (case 1, case 2
) if the function argument is const ref
but by val
works for all cases.
Is there any way other than pass by val
to handle specialization for all cases
(all value types)?