diff --git a/include/boost/core/ref.hpp b/include/boost/core/ref.hpp index 2fd4dc8..c8e7c6a 100644 --- a/include/boost/core/ref.hpp +++ b/include/boost/core/ref.hpp @@ -20,6 +20,7 @@ // // Copyright (C) 2014 Glen Joseph Fernandes // glenfe at live dot com +// Copyright (C) 2014 Agustin Berge // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -65,6 +66,14 @@ public: */ BOOST_FORCEINLINE explicit reference_wrapper(T& t): t_(boost::addressof(t)) {} +# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + /** + @remark Construction from a temporary object is disabled. + */ + BOOST_DELETED_FUNCTION(reference_wrapper(T&& t)) +public: +# endif + /** @return The stored reference. @remark Does not throw. @@ -112,6 +121,15 @@ template BOOST_FORCEINLINE reference_wrapper BOOST_REF_CONST ref( T return reference_wrapper(t); } +/** + @return `ref(t.get())` + @remark Does not throw. +*/ +template BOOST_FORCEINLINE reference_wrapper BOOST_REF_CONST ref( reference_wrapper t ) +{ + return reference_wrapper(t.get()); +} + // cref /** @@ -123,8 +141,45 @@ template BOOST_FORCEINLINE reference_wrapper BOOST_REF_CONST c return reference_wrapper(t); } +/** + @return `cref(t.get())` + @remark Does not throw. +*/ +template BOOST_FORCEINLINE reference_wrapper BOOST_REF_CONST cref( reference_wrapper t ) +{ + return reference_wrapper(t.get()); +} + # undef BOOST_REF_CONST +# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +/** + @cond +*/ +# if defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) +# define BOOST_REF_DELETE +# else +# define BOOST_REF_DELETE = delete +# endif +/** + @endcond +*/ + +/** + @remark Construction from a temporary object is disabled. +*/ +template void ref(T const&& t) BOOST_REF_DELETE; + +/** + @remark Construction from a temporary object is disabled. +*/ +template void cref(T const&& t) BOOST_REF_DELETE; + +# undef BOOST_REF_DELETE + +# endif + // is_reference_wrapper /** diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index e44688e..f98ca08 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -19,6 +19,9 @@ compile-fail checked_delete_fail2.cpp ; compile ref_ct_test.cpp ; run ref_test.cpp ; +compile-fail ref_rv_fail1.cpp ; +compile-fail ref_rv_fail2.cpp ; +compile-fail ref_rv_fail3.cpp ; run eif_constructors.cpp ; run eif_dummy_arg_disambiguation.cpp ; diff --git a/test/ref_rv_fail1.cpp b/test/ref_rv_fail1.cpp new file mode 100644 index 0000000..6e6f706 --- /dev/null +++ b/test/ref_rv_fail1.cpp @@ -0,0 +1,21 @@ +// Copyright 2002-2004 David Abrahams and Aleksey Gurtovoy +// Copyright 2014 Agustin Berge +// +// 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 + +# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +int main() +{ + boost::reference_wrapper r(1); // this should produce an ERROR + + return 0; +} + +# else +# error To fail, this test requires rvalue references +# endif diff --git a/test/ref_rv_fail2.cpp b/test/ref_rv_fail2.cpp new file mode 100644 index 0000000..1ca8222 --- /dev/null +++ b/test/ref_rv_fail2.cpp @@ -0,0 +1,15 @@ +// Copyright 2002-2004 David Abrahams and Aleksey Gurtovoy +// Copyright 2014 Agustin Berge +// +// 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 + +int main() +{ + boost::reference_wrapper r = boost::ref(2); // this should produce an ERROR + + return 0; +} diff --git a/test/ref_rv_fail3.cpp b/test/ref_rv_fail3.cpp new file mode 100644 index 0000000..d93cb4e --- /dev/null +++ b/test/ref_rv_fail3.cpp @@ -0,0 +1,25 @@ +// Copyright 2002-2004 David Abrahams and Aleksey Gurtovoy +// Copyright 2014 Agustin Berge +// +// 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 + +# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +struct X {}; + +X const crv() { return X(); } + +int main() +{ + boost::reference_wrapper r = boost::ref(crv()); // this should produce an ERROR + + return 0; +} + +# else +# error To fail, this test requires rvalue references +# endif