#include <iostream>
using std::cout;
template<typename T>
class A{
public:
template<typename U>
void f(U const&) & ;
template<typename U>
void f(U const&) && ;
};
template<typename T>
template<typename U>
void A<T>::f(U const& x) & { std::cout << "lvalue object\n" ; }
template<typename T>
template<typename U>
void A<T>::f(U const& x) && { std::cout << "rvalue object\n" ; }
// template class A<int> ;
// template void A<int>::f<int>(int const&) & ;
// template void A<float>::f<int>(int const&) &&;
int main(){
A<int> a ;
a.f<int>(2); // lvalue
A<float>().f<int>(1); // rvalue
}
The code runs, other than if I try to break it into separate-compilation (*.hh, *.cc, *.ie and main). The (commented-out) statements will issue a compiler ICE.
I don't see anything wrong with the instantiation syntax. Could someone help me out on this ...