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/*
7Revision history:
825 August 2005 : Initial version.
9*/
10
11#include <boost/core/lightweight_test.hpp>
12
13///////////////////////////////////////////////////////////////////////////////
14// define a user-defined collection type and teach BOOST_FOREACH how to enumerate it
15//
16namespace mine
17{
18 struct dummy {};
19 char * range_begin(mine::dummy&) {return 0;}
20 char const * range_begin(mine::dummy const&) {return 0;}
21 char * range_end(mine::dummy&) {return 0;}
22 char const * range_end(mine::dummy const&) {return 0;}
23}
24
25#include <boost/foreach.hpp>
26
27namespace 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//
44int main()
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 boost::report_errors();
54}
55

source code of boost/libs/foreach/test/user_defined.cpp