I'd like to define multiple ways of assignment operators. Minimal example code.
enum class AssignType {
DeepCopy,
SharedCopy
};
struct Container
{
const char* x;
template<AssignType >
Container& operator=(const Container& other) {
x = other.x; return *this;
}
// ...some specialisations of operator=() could be made
};
int main()
{
Container i1, i2;
i2.operator=<AssignType::DeepCopy>(i1);
i2 =<AssignType::DeepCopy> i1; // line 20
return 0;
}
The g++'s parser gives me an error for line 20. Is there any way to use operators in the "short" form (like in line 20) with explicit templates? C++11 allowed.