From 3044c2beaf731212502ad9680901e4dd163ded5d Mon Sep 17 00:00:00 2001 From: niXman Date: Sat, 11 Feb 2023 02:10:25 +0000 Subject: [PATCH] missing make_pair() for r-value refs (#264) * missing make_pair() for r-value refs hello guys! the `make_pair()` for r-value refs is required for r-value, otherwise `non-copyable` but `movable` can be constructed. thanks! * fix for prev commit conditional support for r-values was fixed * the test case was added * fix for prev commit * Update Jamfile * one more fix for Jamfile * the forgotten r-value ctor was added * ah, they should be conditional --- include/boost/fusion/support/pair.hpp | 11 +++++++++++ test/Jamfile | 4 ++++ test/support/make_pair_r-value.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 test/support/make_pair_r-value.cpp diff --git a/include/boost/fusion/support/pair.hpp b/include/boost/fusion/support/pair.hpp index a4cd1ff0..7d406c63 100644 --- a/include/boost/fusion/support/pair.hpp +++ b/include/boost/fusion/support/pair.hpp @@ -120,6 +120,17 @@ namespace boost { namespace fusion return pair::type>(val); } +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename result_of::make_pair::type + make_pair(Second&& val) + { + return pair::type>( + BOOST_FUSION_FWD_ELEM(Second, val)); + } +#endif + template inline std::ostream& operator<<(std::ostream& os, pair const& p) diff --git a/test/Jamfile b/test/Jamfile index 21944f24..168fdc16 100755 --- a/test/Jamfile +++ b/test/Jamfile @@ -273,6 +273,10 @@ project [ compile support/unused.cpp ] [ compile support/detail/tag_of_fallback.cpp ] + [ compile-fail support/make_pair_r-value.cpp ] + [ compile support/make_pair_r-value.cpp + : [ requires cxx11_rvalue_references ] ] + # [ compile-fail xxx.cpp ] ; diff --git a/test/support/make_pair_r-value.cpp b/test/support/make_pair_r-value.cpp new file mode 100644 index 00000000..ddac6c58 --- /dev/null +++ b/test/support/make_pair_r-value.cpp @@ -0,0 +1,24 @@ +/*============================================================================= + Copyright (c) 2022 niXman (github dot nixman at pm.me) + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ + +#include + +struct noncopyable_type { + noncopyable_type(const noncopyable_type &) = delete; + noncopyable_type& operator=(const noncopyable_type &) = delete; +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + noncopyable_type(noncopyable_type &&) = default; + noncopyable_type& operaotr=(noncopyable_type &&) = default; +#endif +}; + +int main() { + using namespace boost::fusion; + + pair val = make_pair(noncopyable_type{}); + + return 0; +}