I want to write an aggregate template struct with custom assignment operator, like this:
template <typename T>
struct Foo {
Foo() = default;
Foo(const Foo&) = default;
Foo& operator=(const Foo& f) { ... }
...
};
Now, if T
is a const-qualified type I want to have:
Foo& operator=(const Foo& f) = delete;
The only way I can think of is to specialize Foo
struct:
template<T> struct Foo<const T> {
Foo& operator=(const Foo& f) = delete;
... a lot of code ...
}
But to specialize this struct I must copy-paste all the remaining code (aggregate means no inheritance - at least before C++17 and no possibility to move common code to base class).
Is there any better way to do that?