From patchwork Wed Aug 11 16:59:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v3] Update std::forward to N3092 Date: Wed, 11 Aug 2010 06:59:45 -0000 From: Paolo Carlini X-Patchwork-Id: 61488 Message-Id: <4C62D701.5010506@oracle.com> To: Gcc Patch List Cc: libstdc++ ... apparently US 90 is actually getting support, thus to avoid ping - pongs between different versions, I'm reinstating the N2835 version of std::forward which we have in 4_5-branch too (with common_type replacing of course identity, because the latter is gone). Tested x86_64-linux. Paolo. /////////////////////// 2010-08-11 Paolo Carlini * include/bits/move.h (forward): Reinstate the N2835 version. Index: include/bits/move.h =================================================================== --- include/bits/move.h (revision 163100) +++ include/bits/move.h (working copy) @@ -51,17 +51,30 @@ _GLIBCXX_BEGIN_NAMESPACE(std) - /// forward - template - inline typename - enable_if<((std::is_convertible< - typename std::remove_reference<_Up>::type*, - typename std::remove_reference<_Tp>::type*>::value) - && (!std::is_lvalue_reference<_Tp>::value - || std::is_lvalue_reference<_Up>::value)), _Tp&&>::type - forward(_Up&& __u) - { return static_cast<_Tp&&>(__u); } + /// forward (as per N2835) + /// Forward lvalues as rvalues. + template + inline typename enable_if::value, _Tp&&>::type + forward(typename std::common_type<_Tp>::type& __t) + { return static_cast<_Tp&&>(__t); } + /// Forward rvalues as rvalues. + template + inline typename enable_if::value, _Tp&&>::type + forward(typename std::common_type<_Tp>::type&& __t) + { return static_cast<_Tp&&>(__t); } + + // Forward lvalues as lvalues. + template + inline typename enable_if::value, _Tp>::type + forward(typename std::common_type<_Tp>::type __t) + { return __t; } + + // Prevent forwarding rvalues as const lvalues. + template + inline typename enable_if::value, _Tp>::type + forward(typename std::remove_reference<_Tp>::type&& __t) = delete; + /** * @brief Move a value. * @ingroup mutating_algorithms