From 1766ed43a4f85431e0c7cbe3ab9bb3cecfced18c Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Fri, 13 Apr 2012 23:32:34 +0900 Subject: [PATCH] add move_if_noexcept --- sprout/utility/move.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sprout/utility/move.hpp b/sprout/utility/move.hpp index 022c7da2..80f4817c 100644 --- a/sprout/utility/move.hpp +++ b/sprout/utility/move.hpp @@ -9,8 +9,20 @@ namespace sprout { // move // template - inline SPROUT_CONSTEXPR typename std::remove_reference::type&& move(T&& t) SPROUT_NOEXCEPT { - return static_cast::type&&>(t); + inline SPROUT_CONSTEXPR typename std::remove_reference::type&& move(T&& x) SPROUT_NOEXCEPT { + return static_cast::type&&>(x); + } + + // + // move_if_noexcept + // + template + inline SPROUT_CONSTEXPR typename std::conditional< + !std::is_nothrow_move_constructible::value && std::is_copy_constructible::value, + T const&, + T&& + >::type move_if_noexcept(T& x) SPROUT_NOEXCEPT { + return sprout::move(x); } } // namespace sprout