~ubuntu-branches/debian/sid/boost1.49/sid

« back to all changes in this revision

Viewing changes to libs/multi_index/test/test_range.cpp

  • Committer: Package Import Robot
  • Author(s): Steve M. Robbins
  • Date: 2012-02-26 00:31:44 UTC
  • Revision ID: package-import@ubuntu.com-20120226003144-eaytp12cbf6ubpms
Tags: upstream-1.49.0
ImportĀ upstreamĀ versionĀ 1.49.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Boost.MultiIndex test for range().
 
2
 *
 
3
 * Copyright 2003-2010 Joaquin M Lopez Munoz.
 
4
 * Distributed under the Boost Software License, Version 1.0.
 
5
 * (See accompanying file LICENSE_1_0.txt or copy at
 
6
 * http://www.boost.org/LICENSE_1_0.txt)
 
7
 *
 
8
 * See http://www.boost.org/libs/multi_index for library home page.
 
9
 */
 
10
 
 
11
#include "test_range.hpp"
 
12
 
 
13
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
 
14
#include <algorithm>
 
15
#include <functional>
 
16
#include "pre_multi_index.hpp"
 
17
#include <boost/multi_index_container.hpp>
 
18
#include <boost/multi_index/identity.hpp>
 
19
#include <boost/multi_index/ordered_index.hpp>
 
20
#include <boost/preprocessor/seq/enum.hpp>
 
21
#include <boost/test/test_tools.hpp>
 
22
 
 
23
using namespace boost::multi_index;
 
24
 
 
25
typedef multi_index_container<int>  int_set;
 
26
typedef int_set::iterator int_set_iterator;
 
27
 
 
28
#undef CHECK_RANGE
 
29
#define CHECK_RANGE(p,check_seq) \
 
30
{\
 
31
  int v[]={BOOST_PP_SEQ_ENUM(check_seq)};\
 
32
  std::size_t size_v=sizeof(v)/sizeof(int);\
 
33
  BOOST_CHECK(std::size_t(std::distance((p).first,(p).second))==size_v);\
 
34
  BOOST_CHECK(std::equal((p).first,(p).second,&v[0]));\
 
35
}
 
36
 
 
37
#undef CHECK_VOID_RANGE
 
38
#define CHECK_VOID_RANGE(p) BOOST_CHECK((p).first==(p).second)
 
39
 
 
40
void test_range()
 
41
{
 
42
  int_set is;
 
43
 
 
44
  for(int i=1;i<=10;++i)is.insert(i);
 
45
 
 
46
  std::pair<int_set::iterator,int_set::iterator> p;
 
47
 
 
48
  p=is.range(unbounded,unbounded);
 
49
  CHECK_RANGE(p,(1)(2)(3)(4)(5)(6)(7)(8)(9)(10));
 
50
 
 
51
  p=is.range(
 
52
    std::bind1st(std::less<int>(),5), /* 5 < x */
 
53
    unbounded);
 
54
  CHECK_RANGE(p,(6)(7)(8)(9)(10));
 
55
 
 
56
  p=is.range(
 
57
    std::bind1st(std::less_equal<int>(),8), /* 8 <= x */
 
58
    unbounded);
 
59
  CHECK_RANGE(p,(8)(9)(10));
 
60
 
 
61
  p=is.range(
 
62
    std::bind1st(std::less_equal<int>(),11), /* 11 <= x */
 
63
    unbounded);
 
64
  CHECK_VOID_RANGE(p);
 
65
 
 
66
  p=is.range(
 
67
    unbounded,
 
68
    std::bind2nd(std::less<int>(),8)); /* x < 8 */
 
69
  CHECK_RANGE(p,(1)(2)(3)(4)(5)(6)(7));
 
70
 
 
71
  p=is.range(
 
72
    unbounded,
 
73
    std::bind2nd(std::less_equal<int>(),4)); /* x <= 4 */
 
74
  CHECK_RANGE(p,(1)(2)(3)(4));
 
75
 
 
76
  p=is.range(
 
77
    unbounded,
 
78
    std::bind2nd(std::less_equal<int>(),0)); /* x <= 0 */
 
79
  CHECK_VOID_RANGE(p);
 
80
 
 
81
  p=is.range(
 
82
    std::bind1st(std::less<int>(),6),        /* 6 <  x */
 
83
    std::bind2nd(std::less_equal<int>(),9)); /* x <= 9 */
 
84
  CHECK_RANGE(p,(7)(8)(9));
 
85
 
 
86
  p=is.range(
 
87
    std::bind1st(std::less_equal<int>(),4), /* 4 <= x */
 
88
    std::bind2nd(std::less<int>(),5));      /* x <  5 */
 
89
  CHECK_RANGE(p,(4));
 
90
 
 
91
  p=is.range(
 
92
    std::bind1st(std::less_equal<int>(),10),  /* 10 <=  x */
 
93
    std::bind2nd(std::less_equal<int>(),10)); /*  x <= 10 */
 
94
  CHECK_RANGE(p,(10));
 
95
 
 
96
  p=is.range(
 
97
    std::bind1st(std::less<int>(),0),   /* 0 <  x */
 
98
    std::bind2nd(std::less<int>(),11)); /* x < 11 */
 
99
  CHECK_RANGE(p,(1)(2)(3)(4)(5)(6)(7)(8)(9)(10));
 
100
 
 
101
  p=is.range(
 
102
    std::bind1st(std::less<int>(),7),        /* 7 <  x */
 
103
    std::bind2nd(std::less_equal<int>(),7)); /* x <= 7 */
 
104
  CHECK_VOID_RANGE(p);
 
105
  BOOST_CHECK(p.first==is.upper_bound(7));
 
106
 
 
107
  p=is.range(
 
108
    std::bind1st(std::less_equal<int>(),8), /* 8 <= x */
 
109
    std::bind2nd(std::less<int>(),2));      /* x <  2 */
 
110
  CHECK_VOID_RANGE(p);
 
111
  BOOST_CHECK(p.first==is.lower_bound(8));
 
112
 
 
113
  p=is.range(
 
114
    std::bind1st(std::less<int>(),4),  /* 4 < x */
 
115
    std::bind2nd(std::less<int>(),5)); /* x < 5 */
 
116
  CHECK_VOID_RANGE(p);
 
117
  BOOST_CHECK(p.first!=is.end());
 
118
}