Skip to content

Instantly share code, notes, and snippets.

@danlark1
Created April 13, 2020 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danlark1/7e961cd8adc27153e4265d39b2939717 to your computer and use it in GitHub Desktop.
Save danlark1/7e961cd8adc27153e4265d39b2939717 to your computer and use it in GitHub Desktop.
template <class T1, class T2, bool is_reference>
struct MyPairBase;
// Dispatch the reference specialisation and use it as a storage.
template <class T1, class T2>
struct MyPairBase<T1, T2, false> {
T1 a;
T2 b;
MyPairBase& operator=(const MyPairBase& other) = default;
};
template <class T1, class T2>
struct MyPairBase<T1, T2, true> {
T1 a;
T2 b;
MyPairBase& operator=(const MyPairBase& other) {
a = other.a;
b = other.b;
return *this;
}
// Possibly we will need to copy many things there.
};
template <class T1, class T2>
struct MyPair : public MyPairBase<T1, T2, std::is_reference<T1>::value ||
std::is_reference<T2>::value> {
using Base = MyPairBase<T1, T2, std::is_reference<T1>::value ||
std::is_reference<T2>::value>;
// ... all the implementation
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment