From 49b9a8d17f68301e6dfdec7e0fe11f70d89070c0 Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 2 Jun 2015 02:01:32 +0100 Subject: [PATCH] add octa::make_pair and octa::exchange --- octa/algorithm.h | 2 +- octa/utility.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/octa/algorithm.h b/octa/algorithm.h index 63a23ac..f16969f 100644 --- a/octa/algorithm.h +++ b/octa/algorithm.h @@ -373,7 +373,7 @@ namespace octa { __range1.pop_front(); __range2.pop_front(); } - return octa::Pair<_R1, _R2>(__range1, __range2); + return octa::make_pair(__range1, __range2); } template diff --git a/octa/utility.h b/octa/utility.h index 53d832c..8b3429e 100644 --- a/octa/utility.h +++ b/octa/utility.h @@ -30,6 +30,15 @@ namespace octa { return static_cast<_T &&>(__v); } + /* exchange */ + + template + _T exchange(_T &__v, _U &&__nv) { + _T __old = move(__v); + __v = forward<_U>(__nv); + return __old; + } + /* declval */ template AddRvalueReference<_T> declval(); @@ -125,6 +134,32 @@ namespace octa { octa::swap(second, __v.second); } }; + + template struct ReferenceWrapper; + + template + struct __OctaMakePairRetBase { + typedef _T Type; + }; + + template + struct __OctaMakePairRetBase> { + typedef _T &Type; + }; + + template + struct __OctaMakePairRet { + typedef typename __OctaMakePairRetBase>::Type Type; + }; + + template + Pair::Type, + typename __OctaMakePairRet<_U>::Type + > make_pair(_T &&__a, _U &&__b) { + return Pair::Type, + typename __OctaMakePairRet<_U>::Type + >(forward<_T>(__a), forward<_U>(__b));; + } } #endif \ No newline at end of file