Ticket #5475: foreach_add_new_tests.patch
File foreach_add_new_tests.patch, 20.7 KB (added by , 11 years ago) |
---|
-
libs/foreach/test/cxx11_lambda.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 <vector> 12 #include <boost/config.hpp> 13 #include <boost/test/minimal.hpp> 14 #include <boost/foreach.hpp> 15 16 #ifdef BOOST_NO_LAMBDAS 17 int test_main( int, char*[] ) 18 { 19 return 0; 20 } 21 #else 22 23 /////////////////////////////////////////////////////////////////////////////// 24 // test_main 25 // 26 int test_main( int, char*[] ) 27 { 28 int counter = 0; 29 30 BOOST_FOREACH(int i, [](){ return std::vector<int>(4, 4); }()) 31 { 32 counter += i; 33 } 34 35 BOOST_CHECK(16 == counter); 36 37 return 0; 38 } 39 40 #endif -
libs/foreach/test/pair_byval_r.cpp
33 33 // 34 34 int test_main( int, char*[] ) 35 35 { 36 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 36 37 boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_pair); 37 38 (void)p; 38 39 #endif 39 40 // non-const containers by value 40 41 BOOST_CHECK(sequence_equal_byval_n_r(my_pair, "\5\4\3\2\1")); 41 42 -
libs/foreach/test/array_byval.cpp
32 32 // 33 33 int test_main( int, char*[] ) 34 34 { 35 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 35 36 boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_array); 36 37 (void)p; 38 #endif 37 39 // non-const containers by value 38 40 BOOST_CHECK(sequence_equal_byval_n(my_array, "\1\2\3\4\5")); 39 41 -
libs/foreach/test/stl_byval_r.cpp
48 48 // 49 49 int test_main( int, char*[] ) 50 50 { 51 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 51 52 boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_list); 52 53 (void)p; 53 54 #endif 54 55 // non-const containers by value 55 56 BOOST_CHECK(sequence_equal_byval_n_r(my_list, "\5\4\3\2\1")); 56 57 -
libs/foreach/test/pair_byval.cpp
33 33 // 34 34 int test_main( int, char*[] ) 35 35 { 36 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 36 37 boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_pair); 37 38 (void)p; 38 39 #endif 39 40 // non-const containers by value 40 41 BOOST_CHECK(sequence_equal_byval_n(my_pair, "\1\2\3\4\5")); 41 42 -
libs/foreach/test/cstr_byval_r.cpp
33 33 // 34 34 int test_main( int, char*[] ) 35 35 { 36 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 36 37 boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_ntcs); 37 38 (void)p; 38 39 #endif 39 40 // non-const containers by value 40 41 BOOST_CHECK(sequence_equal_byval_n_r(my_ntcs, "\5\4\3\2\1")); 41 42 -
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 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 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/rvalue_nonconst_access_fail.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 <vector> 12 #include <boost/test/minimal.hpp> 13 #include <boost/foreach.hpp> 14 15 #ifdef BOOST_FOREACH_NO_RVALUE_DETECTION 16 # error Expected failure : rvalues disallowed 17 #else 18 19 /////////////////////////////////////////////////////////////////////////////// 20 // test_main 21 // 22 int test_main( int, char*[] ) 23 { 24 BOOST_FOREACH(int &i, std::vector<int>(4, 4)) 25 { 26 (void)i; 27 } 28 29 return 0; 30 } 31 32 #endif -
libs/foreach/test/stl_byval.cpp
48 48 // 49 49 int test_main( int, char*[] ) 50 50 { 51 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 51 52 boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_list); 52 53 (void)p; 53 54 #endif 54 55 // non-const containers by value 55 56 BOOST_CHECK(sequence_equal_byval_n(my_list, "\1\2\3\4\5")); 56 57 -
libs/foreach/test/char_array_fail.cpp
1 // noncopyable.cpp 2 /// 3 // (C) Copyright Eric Niebler 2004. 4 // Use, modification and distribution are subject to the 5 // Boost Software License, Version 1.0. (See accompanying file 6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 8 /* 9 Revision history: 10 21 December 2005 : Initial version. 11 */ 12 13 #include <boost/foreach.hpp> 14 15 /////////////////////////////////////////////////////////////////////////////// 16 // main 17 // 18 int main( int, char*[] ) 19 { 20 char ar[] = "\1\2\3\4\5"; 21 BOOST_FOREACH( char ch, ar ) 22 { 23 (void)ch; 24 } 25 26 return 0; 27 } -
libs/foreach/test/cstr_byval.cpp
33 33 // 34 34 int test_main( int, char*[] ) 35 35 { 36 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 36 37 boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_ntcs); 37 38 (void)p; 38 39 #endif 39 40 // non-const containers by value 40 41 BOOST_CHECK(sequence_equal_byval_n(my_ntcs, "\1\2\3\4\5")); 41 42 -
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 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 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_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/rvalue_nonconst_access_r_fail.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 <vector> 12 #include <boost/test/minimal.hpp> 13 #include <boost/foreach.hpp> 14 15 #ifdef BOOST_FOREACH_NO_RVALUE_DETECTION 16 # error Expected failure : rvalues disallowed 17 #else 18 19 /////////////////////////////////////////////////////////////////////////////// 20 // test_main 21 // 22 int test_main( int, char*[] ) 23 { 24 BOOST_REVERSE_FOREACH(int &i, std::vector<int>(4, 4)) 25 { 26 (void)i; 27 } 28 29 return 0; 30 } 31 32 #endif -
libs/foreach/test/Jamfile.v2
33 33 [ run dependent_type.cpp ] 34 34 [ run misc.cpp ] 35 35 [ compile noncopyable.cpp ] 36 [ run noncopyable_rvalue_const.cpp ] 37 [ run noncopyable_rvalue_nonconst.cpp ] 38 [ run noncopyable_rvalue_const_r.cpp ] 39 [ run noncopyable_rvalue_nonconst_r.cpp ] 40 [ run cxx11_gcc_workaround.cpp ] 41 [ run cxx11_gcc_workaround_r.cpp ] 42 [ run cxx11_lambda.cpp ] 43 [ run cxx11_lambda_r.cpp ] 44 [ compile-fail char_array_fail.cpp ] 45 [ compile-fail char_array_r_fail.cpp ] 46 [ compile-fail rvalue_nonconst_access_fail.cpp ] 47 [ compile-fail rvalue_nonconst_access_r_fail.cpp ] 36 48 ; -
libs/foreach/test/cxx11_gcc_workaround_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 <vector> 12 #include <boost/config.hpp> 13 #include <boost/test/minimal.hpp> 14 #include <boost/foreach.hpp> 15 16 #ifdef BOOST_NO_RVALUE_REFERENCES 17 int test_main( int, char*[] ) 18 { 19 return 0; 20 } 21 #else 22 23 template <typename T> 24 T const add_const_if_rvalue(T&& t) 25 { 26 return t; 27 } 28 29 template <typename T> 30 void f() 31 { 32 int counter = 0; 33 34 BOOST_FOREACH(int i, add_const_if_rvalue(std::vector<int>(4, 4))) 35 { 36 counter += i; 37 } 38 39 BOOST_CHECK(16 == counter); 40 } 41 42 /////////////////////////////////////////////////////////////////////////////// 43 // test_main 44 // 45 int test_main( int, char*[] ) 46 { 47 f<void>(); 48 49 return 0; 50 } 51 52 #endif -
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 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 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/cxx11_lambda_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 <vector> 12 #include <boost/config.hpp> 13 #include <boost/test/minimal.hpp> 14 #include <boost/foreach.hpp> 15 16 #ifdef BOOST_NO_LAMBDAS 17 int test_main( int, char*[] ) 18 { 19 return 0; 20 } 21 #else 22 23 /////////////////////////////////////////////////////////////////////////////// 24 // test_main 25 // 26 int test_main( int, char*[] ) 27 { 28 int counter = 0; 29 30 BOOST_REVERSE_FOREACH(int i, [](){ return std::vector<int>(4, 4); }()) 31 { 32 counter += i; 33 } 34 35 BOOST_CHECK(16 == counter); 36 37 return 0; 38 } 39 40 #endif -
libs/foreach/test/char_array_r_fail.cpp
1 // noncopyable.cpp 2 /// 3 // (C) Copyright Eric Niebler 2004. 4 // Use, modification and distribution are subject to the 5 // Boost Software License, Version 1.0. (See accompanying file 6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 8 /* 9 Revision history: 10 21 December 2005 : Initial version. 11 */ 12 13 #include <boost/foreach.hpp> 14 15 /////////////////////////////////////////////////////////////////////////////// 16 // main 17 // 18 int main( int, char*[] ) 19 { 20 char ar[] = "\1\2\3\4\5"; 21 BOOST_REVERSE_FOREACH( char ch, ar ) 22 { 23 (void)ch; 24 } 25 26 return 0; 27 } -
libs/foreach/test/cxx11_gcc_workaround.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 <vector> 12 #include <boost/config.hpp> 13 #include <boost/test/minimal.hpp> 14 #include <boost/foreach.hpp> 15 16 #ifdef BOOST_NO_RVALUE_REFERENCES 17 int test_main( int, char*[] ) 18 { 19 return 0; 20 } 21 #else 22 23 template <typename T> 24 T const add_const_if_rvalue(T&& t) 25 { 26 return t; 27 } 28 29 template <typename T> 30 void f() 31 { 32 int counter = 0; 33 34 BOOST_FOREACH(int i, add_const_if_rvalue(std::vector<int>(4, 4))) 35 { 36 counter += i; 37 } 38 39 BOOST_CHECK(16 == counter); 40 } 41 42 /////////////////////////////////////////////////////////////////////////////// 43 // test_main 44 // 45 int test_main( int, char*[] ) 46 { 47 f<void>(); 48 49 return 0; 50 } 51 52 #endif -
libs/foreach/test/array_byval_r.cpp
32 32 // 33 33 int test_main( int, char*[] ) 34 34 { 35 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 35 36 boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_array); 36 37 (void)p; 37 38 #endif 38 39 // non-const containers by value 39 40 BOOST_CHECK(sequence_equal_byval_n_r(my_array, "\5\4\3\2\1")); 40 41 -
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 #if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND) 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