Created
April 13, 2020 16:42
-
-
Save danlark1/8b412dfdda26e0577aeb74522aaa186b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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