Ticket #7911: varant_noexcept.patch
File varant_noexcept.patch, 3.8 KB (added by , 9 years ago) |
---|
-
boost/variant/variant.hpp
226 226 227 227 #endif // BOOST_MPL_CFG_MSVC_60_ETI_BUG workaround 228 228 229 #ifndef BOOST_NO_CXX11_NOEXCEPT 229 230 /////////////////////////////////////////////////////////////////////////////// 231 // (detail) metafunction is_variant_move_noexcept 232 // 233 // Returns true_type if all the types are nothrow move constructible. 234 // 235 template <class Types> 236 struct is_variant_move_noexcept { 237 typedef typename boost::mpl::find_if< 238 Types, mpl::not_<boost::is_nothrow_move_constructible<boost::mpl::_1> > 239 >::type iterator_t; 240 241 typedef typename boost::mpl::end<Types>::type end_t; 242 typedef typename boost::is_same< 243 iterator_t, end_t 244 >::type type; 245 }; 246 #endif // BOOST_NO_CXX11_NOEXCEPT 247 248 /////////////////////////////////////////////////////////////////////////////// 230 249 // (detail) metafunction make_storage 231 250 // 232 251 // Provides an aligned storage type capable of holding any of the types … … 1289 1308 internal_types, never_uses_backup_flag 1290 1309 >::type storage_t; 1291 1310 1311 #ifndef BOOST_NO_CXX11_NOEXCEPT 1312 typedef typename detail::variant::is_variant_move_noexcept< 1313 internal_types 1314 > variant_move_noexcept; 1315 #endif 1316 1292 1317 private: // helpers, for representation (below) 1293 1318 1294 1319 // which_ on: … … 1375 1400 1376 1401 public: // structors 1377 1402 1378 ~variant() 1403 ~variant() BOOST_NOEXCEPT 1379 1404 { 1380 1405 destroy_content(); 1381 1406 } … … 1766 1791 } 1767 1792 1768 1793 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES 1769 variant(variant&& operand) 1794 variant(variant&& operand) BOOST_NOEXCEPT_IF(variant_move_noexcept::type::value) 1770 1795 { 1771 1796 // Move the value of operand into *this... 1772 1797 detail::variant::move_into visitor( storage_.address() ); … … 2177 2202 } 2178 2203 2179 2204 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES 2180 variant& operator=(variant&& rhs) 2205 variant& operator=(variant&& rhs) BOOST_NOEXCEPT_IF(variant_move_noexcept::type::value) 2181 2206 { 2182 2207 variant_assign( detail::variant::move(rhs) ); 2183 2208 return *this; -
libs/variant/test/rvalue_test.cpp
3 3 // See http://www.boost.org for updates, documentation, and revision history. 4 4 //----------------------------------------------------------------------------- 5 5 // 6 // Copyright (c) 2012 7 // Antony Polukhin 6 // Copyright (c) 2012-2013 Antony Polukhin 8 7 // 9 8 // Distributed under the Boost Software License, Version 1.0. (See 10 9 // accompanying file LICENSE_1_0.txt or copy at … … 14 13 15 14 #include "boost/test/minimal.hpp" 16 15 #include "boost/variant.hpp" 16 #include "boost/type_traits/is_nothrow_move_assignable.hpp" 17 17 18 18 // This test requires rvalue references support 19 19 … … 34 34 BOOST_CHECK(true); 35 35 } 36 36 37 void run_moves_are_noexcept() 38 { 39 BOOST_CHECK(true); 40 } 41 37 42 #else 38 43 39 44 class move_copy_conting_class { … … 177 182 BOOST_CHECK(vi.which() == 1); 178 183 } 179 184 185 void run_moves_are_noexcept() { 186 #ifndef BOOST_NO_CXX11_NOEXCEPT 187 typedef boost::variant<int, short, double> variant_noexcept_t; 188 BOOST_CHECK(boost::is_nothrow_move_assignable<variant_noexcept_t>::value); 189 BOOST_CHECK(boost::is_nothrow_move_constructible<variant_noexcept_t>::value); 190 191 typedef boost::variant<int, short, double, move_only_structure> variant_except_t; 192 BOOST_CHECK(!boost::is_nothrow_move_assignable<variant_except_t>::value); 193 BOOST_CHECK(!boost::is_nothrow_move_constructible<variant_except_t>::value); 180 194 #endif 195 } 181 196 197 #endif 182 198 199 183 200 int test_main(int , char* []) 184 201 { 185 202 run(); 186 203 run1(); 187 204 run_move_only(); 205 run_moves_are_noexcept(); 188 206 return 0; 189 } 190 No newline at end of file 207 }