Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@danlark1
Created April 13, 2020 16:42
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/8b412dfdda26e0577aeb74522aaa186b to your computer and use it in GitHub Desktop.
Save danlark1/8b412dfdda26e0577aeb74522aaa186b to your computer and use it in GitHub Desktop.
#include <type_traits>
template<class T1, class T2>
struct MyPair {
T1 first;
T2 second;
static constexpr bool has_references = std::is_reference_v<T1> ||
std::is_reference_v<T2>;
MyPair(const T1& x, const T2& y) : first(x), second(y) {}
MyPair& operator=(const MyPair&) requires(!has_references) = default;
MyPair& operator=(const MyPair& other) requires(has_references) {
first = other.first;
second = other.second;
return *this;
}
};
int main() {
int x = 10;
MyPair<int&, int> a(x, 5);
MyPair<int&, int> b(x, 10);
b = a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment