Skip to content

Instantly share code, notes, and snippets.

@zoecarver
Last active June 8, 2019 00:02
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 zoecarver/eac87b03aadaf5d70ffdf9925062569e to your computer and use it in GitHub Desktop.
Save zoecarver/eac87b03aadaf5d70ffdf9925062569e to your computer and use it in GitHub Desktop.
Uses allocator construction issue with perfect forwarding
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));
}
@zoecarver
Copy link
Author

Ignore the spacing. Github won't let me change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment