1// (C) Copyright Eric Niebler 2004.
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 13 December 2004 : Initial version.
9 25 August 2005 : Initial version.
10*/
11
12#include <boost/core/lightweight_test.hpp>
13#include <boost/foreach.hpp>
14
15///////////////////////////////////////////////////////////////////////////////
16// define the container types, used by utility.hpp to generate the helper functions
17typedef std::pair<int*,int*> foreach_container_type;
18typedef std::pair<int const*,int const*> const foreach_const_container_type;
19typedef int foreach_value_type;
20typedef int &foreach_reference_type;
21typedef int const &foreach_const_reference_type;
22
23#include "./utility.hpp"
24
25///////////////////////////////////////////////////////////////////////////////
26// define some containers
27//
28int my_array[] = { 1,2,3,4,5 };
29std::pair<int*,int*> my_pair(my_array,my_array+5);
30std::pair<int const*,int const*> const my_const_pair(my_array,my_array+5);
31
32///////////////////////////////////////////////////////////////////////////////
33// test_main
34//
35int main()
36{
37 // non-const containers by reference
38 BOOST_TEST(sequence_equal_byref_n(my_pair, "\1\2\3\4\5"));
39
40 // const containers by reference
41 BOOST_TEST(sequence_equal_byref_c(my_const_pair, "\1\2\3\4\5"));
42
43 // mutate the mutable collections
44 mutate_foreach_byref(rng&: my_pair);
45
46 // compare the mutated collections to the actual results
47 BOOST_TEST(sequence_equal_byref_n(my_pair, "\2\3\4\5\6"));
48
49 return boost::report_errors();
50}
51

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