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 13 /////////////////////////////////////////////////////////////////////////////// 14 // define a user-defined collection type and teach BOOST_FOREACH how to enumerate it 15 // 16 namespace mine 17 { 18 struct dummy {}; range_begin(mine::dummy &)19 char * range_begin(mine::dummy&) {return 0;} range_begin(mine::dummy const &)20 char const * range_begin(mine::dummy const&) {return 0;} range_end(mine::dummy &)21 char * range_end(mine::dummy&) {return 0;} range_end(mine::dummy const &)22 char const * range_end(mine::dummy const&) {return 0;} 23 } 24 25 #include <boost/foreach.hpp> 26 27 namespace boost 28 { 29 template<> 30 struct range_mutable_iterator<mine::dummy> 31 { 32 typedef char * type; 33 }; 34 template<> 35 struct range_const_iterator<mine::dummy> 36 { 37 typedef char const * type; 38 }; 39 } 40 41 /////////////////////////////////////////////////////////////////////////////// 42 // test_main 43 // test_main(int,char * [])44int test_main( int, char*[] ) 45 { 46 // loop over a user-defined type (just make sure this compiles) 47 mine::dummy d; 48 BOOST_FOREACH( char c, d ) 49 { 50 ((void)c); // no-op 51 } 52 53 return 0; 54 } 55