Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Unified Diff: base/tuple.h

Issue 2047013002: Add base::get to support rvalue-reference tuple (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +test case Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/tuple_unittest.cc » ('j') | styleguide/c++/c++11.html » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/tuple.h
diff --git a/base/tuple.h b/base/tuple.h
index 62344a1233916317b5ff96659fc5370daa5c4260..e82f2e5f06ad8860f722879b44bfef1e150c23f1 100644
--- a/base/tuple.h
+++ b/base/tuple.h
@@ -104,6 +104,20 @@ struct MakeIndexSequenceImpl<N, Ns...>
#endif // defined(OS_WIN) && defined(_PREFAST_)
+// std::get() in <=libstdc++-4.6 returns an lvalue-reference for
+// rvalue-reference of a tuple, where an rvalue-reference is expected.
+template <size_t I, typename... Ts>
+typename std::tuple_element<I, std::tuple<Ts...>>::type&& get(
+ std::tuple<Ts...>&& t) {
+ using ElemType = typename std::tuple_element<I, std::tuple<Ts...>>::type;
+ return std::forward<ElemType>(std::get<I>(t));
+}
+
+template <size_t I, typename T>
+auto get(T& t) -> decltype(std::get<I>(t)) {
+ return std::get<I>(t);
+}
+
template <size_t N>
using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type;
« no previous file with comments | « no previous file | base/tuple_unittest.cc » ('j') | styleguide/c++/c++11.html » ('J')

Powered by Google App Engine
This is Rietveld 408576698