Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
values-inter.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Copyright:
7 * Christian Schulte, 2008
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode { namespace Iter { namespace Values {
35
42 template<class I, class J>
43 class Inter {
44 protected:
46 I i;
48 J j;
50 void next(void);
51 public:
53
54
55 Inter(void);
57 Inter(I& i, J& j);
59 void init(I& i, J& j);
61
63
64
65 bool operator ()(void) const;
67 void operator ++(void);
69
71
72
73 int val(void) const;
75 };
76
77
78 template<class I, class J>
81
82 template<class I, class J>
83 forceinline void
85 do {
86 while (i() && j() && (i.val() < j.val()))
87 ++i;
88 while (i() && j() && (j.val() < i.val()))
89 ++j;
90 } while (i() && j() && (i.val() != j.val()));
91 }
92
93 template<class I, class J>
94 inline void
95 Inter<I,J>::init(I& i0, J& j0) {
96 i=i0; j=j0; next();
97 }
98
99 template<class I, class J>
101 Inter<I,J>::Inter(I& i0, J& j0) : i(i0), j(j0) {
102 next();
103 }
104
105 template<class I, class J>
106 forceinline void
108 ++i; ++j; next();
109 }
110
111 template<class I, class J>
112 forceinline bool
114 return i() && j();
115 }
116
117 template<class I, class J>
118 forceinline int
119 Inter<I,J>::val(void) const {
120 assert(i.val() == j.val());
121 return i.val();
122 }
123
124}}}
125
126// STATISTICS: iter-any
Value iterator for the intersection of two value iterators.
Inter(void)
Default constructor.
int val(void) const
Return current value.
void next(void)
Find next element from intersection.
void init(I &i, J &j)
Initialize with values from i and j.
bool operator()(void) const
Test whether iterator is still at a value or done.
void operator++(void)
Move iterator to next value (if possible)
Gecode toplevel namespace
#define forceinline
Definition config.hpp:187