Last active
June 8, 2019 00:02
-
-
Save zoecarver/eac87b03aadaf5d70ffdf9925062569e to your computer and use it in GitHub Desktop.
Uses allocator construction issue with perfect forwarding
This file contains hidden or 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
using namespace std; | |
template<class T1, class T2> | |
void join(T1&& t1, T2&& t2) | |
{ | |
static_assert(is_same<decltype(get<0>(t1)), int&&>::value); // fails | |
} | |
template<class T1, class T2> | |
auto foward_pair(pair<T1, T2>&& p) | |
{ | |
static_assert(is_same<T1, int&&>::value); | |
return join(forward_as_tuple(move(p).first), | |
forward_as_tuple(move(p).second)); | |
} | |
int main() | |
{ | |
int x = 42; | |
pair<int&&, int&&> p = make_pair(std::move(x), std::move(x)); | |
foward_pair(move(p)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ignore the spacing. Github won't let me change it.