Ticket #5475: test_noncopyable_rvalue.patch
File test_noncopyable_rvalue.patch, 7.6 KB (added by , 12 years ago) |
---|
-
libs/foreach/test/noncopyable_rvalue_nonconst_r.cpp
1 // (C) Copyright Eric Niebler 2005. 2 // Use, modification and distribution are subject to the 3 // Boost Software License, Version 1.0. (See accompanying file 4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 /* 7 Revision history: 8 25 August 2005 : Initial version. 9 */ 10 11 #include <boost/test/minimal.hpp> 12 #include <boost/foreach.hpp> 13 14 #ifndef BOOST_FOREACH_USE_RVALUE_REFERENCE_BINDING 15 # error Expected failure : non-copyable rvalues disallowed 16 #else 17 18 class my_container 19 { 20 public: 21 my_container() 22 { 23 array_[0] = 1; 24 array_[1] = 2; 25 array_[2] = 3; 26 array_[3] = 4; 27 array_[4] = 5; 28 } 29 30 typedef int* iterator; 31 typedef int const* const_iterator; 32 33 iterator begin() { return array_; } 34 const_iterator begin() const { return array_; } 35 36 iterator end() { return array_ + 5; } 37 const_iterator end() const { return array_ + 5; } 38 39 private: 40 int array_[5]; 41 42 // non-copyable 43 my_container(my_container const &); 44 my_container &operator =(my_container const &); 45 46 // non-movable 47 my_container(my_container &&); 48 my_container &operator =(my_container &&); 49 }; 50 51 /////////////////////////////////////////////////////////////////////////////// 52 // test_main 53 // 54 int test_main( int, char*[] ) 55 { 56 int counter = 0; 57 58 BOOST_REVERSE_FOREACH(int i, my_container()) 59 { 60 counter += i; 61 } 62 63 BOOST_CHECK(15 == counter); 64 65 return 0; 66 } 67 68 #endif -
libs/foreach/test/noncopyable_rvalue_nonconst.cpp
1 // (C) Copyright Eric Niebler 2005. 2 // Use, modification and distribution are subject to the 3 // Boost Software License, Version 1.0. (See accompanying file 4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 /* 7 Revision history: 8 25 August 2005 : Initial version. 9 */ 10 11 #include <boost/test/minimal.hpp> 12 #include <boost/foreach.hpp> 13 14 #ifndef BOOST_FOREACH_USE_RVALUE_REFERENCE_BINDING 15 # error Expected failure : non-copyable rvalues disallowed 16 #else 17 18 class my_container 19 { 20 public: 21 my_container() 22 { 23 array_[0] = 1; 24 array_[1] = 2; 25 array_[2] = 3; 26 array_[3] = 4; 27 array_[4] = 5; 28 } 29 30 typedef int* iterator; 31 typedef int const* const_iterator; 32 33 iterator begin() { return array_; } 34 const_iterator begin() const { return array_; } 35 36 iterator end() { return array_ + 5; } 37 const_iterator end() const { return array_ + 5; } 38 39 private: 40 int array_[5]; 41 42 // non-copyable 43 my_container(my_container const &); 44 my_container &operator =(my_container const &); 45 46 // non-movable 47 my_container(my_container &&); 48 my_container &operator =(my_container &&); 49 }; 50 51 /////////////////////////////////////////////////////////////////////////////// 52 // test_main 53 // 54 int test_main( int, char*[] ) 55 { 56 int counter = 0; 57 58 BOOST_REVERSE_FOREACH(int i, my_container()) 59 { 60 counter += i; 61 } 62 63 BOOST_CHECK(15 == counter); 64 65 return 0; 66 } 67 68 #endif -
libs/foreach/test/Jamfile.v2
32 32 [ run rvalue_nonconst_r.cpp ] 33 33 [ run dependent_type.cpp ] 34 34 [ run misc.cpp ] 35 [ run noncopyable_rvalue_const.cpp ] 36 [ run noncopyable_rvalue_nonconst.cpp ] 37 [ run noncopyable_rvalue_const_r.cpp ] 38 [ run noncopyable_rvalue_nonconst_r.cpp ] 35 39 [ compile noncopyable.cpp ] 36 40 ; -
libs/foreach/test/noncopyable_rvalue_const_r.cpp
1 // (C) Copyright Eric Niebler 2005. 2 // Use, modification and distribution are subject to the 3 // Boost Software License, Version 1.0. (See accompanying file 4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 /* 7 Revision history: 8 25 August 2005 : Initial version. 9 */ 10 11 #include <boost/test/minimal.hpp> 12 #include <boost/foreach.hpp> 13 14 #ifndef BOOST_FOREACH_USE_RVALUE_REFERENCE_BINDING 15 # error Expected failure : non-copyable rvalues disallowed 16 #else 17 18 class my_container 19 { 20 public: 21 my_container() 22 { 23 array_[0] = 1; 24 array_[1] = 2; 25 array_[2] = 3; 26 array_[3] = 4; 27 array_[4] = 5; 28 } 29 30 typedef int* iterator; 31 typedef int const* const_iterator; 32 33 iterator begin() { return array_; } 34 const_iterator begin() const { return array_; } 35 36 iterator end() { return array_ + 5; } 37 const_iterator end() const { return array_ + 5; } 38 39 private: 40 int array_[5]; 41 42 // non-copyable 43 my_container(my_container const &); 44 my_container &operator =(my_container const &); 45 46 // non-movable 47 my_container(my_container &&); 48 my_container &operator =(my_container &&); 49 }; 50 51 typedef my_container const const_my_container; 52 53 /////////////////////////////////////////////////////////////////////////////// 54 // test_main 55 // 56 int test_main( int, char*[] ) 57 { 58 int counter = 0; 59 60 BOOST_REVERSE_FOREACH(int i, const_my_container()) 61 { 62 counter += i; 63 } 64 65 BOOST_CHECK(15 == counter); 66 67 return 0; 68 } 69 70 #endif -
libs/foreach/test/noncopyable_rvalue_const.cpp
1 // (C) Copyright Eric Niebler 2005. 2 // Use, modification and distribution are subject to the 3 // Boost Software License, Version 1.0. (See accompanying file 4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 /* 7 Revision history: 8 25 August 2005 : Initial version. 9 */ 10 11 #include <boost/test/minimal.hpp> 12 #include <boost/foreach.hpp> 13 14 #ifndef BOOST_FOREACH_USE_RVALUE_REFERENCE_BINDING 15 # error Expected failure : non-copyable rvalues disallowed 16 #else 17 18 class my_container 19 { 20 public: 21 my_container() 22 { 23 array_[0] = 1; 24 array_[1] = 2; 25 array_[2] = 3; 26 array_[3] = 4; 27 array_[4] = 5; 28 } 29 30 typedef int* iterator; 31 typedef int const* const_iterator; 32 33 iterator begin() { return array_; } 34 const_iterator begin() const { return array_; } 35 36 iterator end() { return array_ + 5; } 37 const_iterator end() const { return array_ + 5; } 38 39 private: 40 int array_[5]; 41 42 // non-copyable 43 my_container(my_container const &); 44 my_container &operator =(my_container const &); 45 46 // non-movable 47 my_container(my_container &&); 48 my_container &operator =(my_container &&); 49 }; 50 51 typedef my_container const const_my_container; 52 53 /////////////////////////////////////////////////////////////////////////////// 54 // test_main 55 // 56 int test_main( int, char*[] ) 57 { 58 int counter = 0; 59 60 BOOST_FOREACH(int i, const_my_container()) 61 { 62 counter += i; 63 } 64 65 BOOST_CHECK(15 == counter); 66 67 return 0; 68 } 69 70 #endif