From 75e27a14b017c3778a423bd26f2f876f5cca2a78 Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 2 May 2016 18:21:54 +0100 Subject: [PATCH] overload rvalue refs to const for tuple --- ostd/array.hh | 7 ++++++- ostd/internal/tuple.hh | 9 +++++++++ ostd/range.hh | 4 ++-- ostd/tuple.hh | 11 ++++++++++- ostd/utility.hh | 13 +++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ostd/array.hh b/ostd/array.hh index 87da0e6..74eb61a 100644 --- a/ostd/array.hh +++ b/ostd/array.hh @@ -96,7 +96,12 @@ const TupleElement> &get(const Array &a) { template TupleElement> &&get(Array &&a) { - return a[I]; + return move(a.p_buf[I]); +} + +template +const TupleElement> &&get(const Array &&a) { + return move(a.p_buf[I]); } template diff --git a/ostd/internal/tuple.hh b/ostd/internal/tuple.hh index eafe244..4e8143b 100644 --- a/ostd/internal/tuple.hh +++ b/ostd/internal/tuple.hh @@ -64,6 +64,9 @@ const TupleElement> &get(const Tuple &); template TupleElement> &&get(Tuple &&); +template +const TupleElement> &&get(const Tuple &&); + /* pair specializations */ template constexpr bool IsTupleLike> = true; @@ -77,6 +80,9 @@ const TupleElement> &get(const Pair &); template TupleElement> &&get(Pair &&); +template +const TupleElement> &&get(const Pair &&); + /* array specializations */ template constexpr bool IsTupleLike> = true; @@ -90,6 +96,9 @@ const T &get(const Array &); template T &&get(Array &&); +template +const T &&get(const Array &&); + /* make tuple indices */ namespace detail { diff --git a/ostd/range.hh b/ostd/range.hh index 7351b32..09a3af6 100644 --- a/ostd/range.hh +++ b/ostd/range.hh @@ -609,12 +609,12 @@ inline auto chunks(T n) { namespace detail { template inline auto join_proxy(T &&obj, Tuple &&tup, TupleIndices) { - return obj.join(forward(get(tup))...); + return obj.join(forward(get(forward>(tup)))...); } template inline auto zip_proxy(T &&obj, Tuple &&tup, TupleIndices) { - return obj.zip(forward(get(tup))...); + return obj.zip(forward(get(forward>(tup)))...); } } diff --git a/ostd/tuple.hh b/ostd/tuple.hh index 25d32fa..1146946 100644 --- a/ostd/tuple.hh +++ b/ostd/tuple.hh @@ -277,6 +277,9 @@ class Tuple { template friend TupleElement> &&get(Tuple &&); + template + friend const TupleElement> &&get(const Tuple &&); + public: template)...> @@ -421,7 +424,13 @@ inline const TupleElement> &get(const Tuple &t) { template inline TupleElement> &&get(Tuple &&t) { using Type = TupleElement>; - return ((detail::TupleLeaf &&)t.p_base).get(); + return (Type &&)(((detail::TupleLeaf &&)t.p_base).get()); +} + +template +inline const TupleElement> &&get(const Tuple &&t) { + using Type = TupleElement>; + return (const Type &&)(((const detail::TupleLeaf &&)t.p_base).get()); } /* tie */ diff --git a/ostd/utility.hh b/ostd/utility.hh index b44b37b..65481d6 100644 --- a/ostd/utility.hh +++ b/ostd/utility.hh @@ -231,6 +231,10 @@ namespace detail { static const T &get(const Pair &p) { return p.first; } template static T &&get(Pair &&p) { return forward(p.first); } + template + static const T &&get(const Pair &&p) { + return forward(p.first); + } }; template<> struct GetPair<1> { @@ -240,6 +244,10 @@ namespace detail { static const U &get(const Pair &p) { return p.second; } template static U &&get(Pair &&p) { return forward(p.second); } + template + static const T &&get(const Pair &&p) { + return forward(p.second); + } }; } @@ -258,6 +266,11 @@ TupleElement> &&get(Pair &&p) { return detail::GetPair::get(move(p)); } +template +const TupleElement> &&get(const Pair &&p) { + return detail::GetPair::get(move(p)); +} + namespace detail { template, RemoveCv>,