QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
set_assign.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
2// vim:tabstop=4:shiftwidth=4:expandtab:
3
4/*
5 * Copyright (C) 2004-2008 Wu Yongwei <adah at users dot sourceforge dot net>
6 *
7 * This software is provided 'as-is', without any express or implied
8 * warranty. In no event will the authors be held liable for any
9 * damages arising from the use of this software.
10 *
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute
13 * it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must
16 * not claim that you wrote the original software. If you use this
17 * software in a product, an acknowledgement in the product
18 * documentation would be appreciated but is not required.
19 * 2. Altered source versions must be plainly marked as such, and must
20 * not be misrepresented as being the original software.
21 * 3. This notice may not be removed or altered from any source
22 * distribution.
23 *
24 * This file is part of Stones of Nvwa:
25 * http://sourceforge.net/projects/nvwa
26 *
27 */
28
40#ifndef QT_NO_DEBUG
41#ifndef _QX_MODE_RELEASE
42#if _QX_USE_MEM_LEAK_DETECTION
43
44#ifndef _SET_ASSIGN_H
45#define _SET_ASSIGN_H
46
47#ifdef _MSC_VER
48#pragma once
49#endif
50
51#include <algorithm>
52
53namespace qx {
54namespace memory {
55
56template <class _Container, class _InputIter>
57_Container& set_assign_union(_Container& __dest,
58 _InputIter __first,
59 _InputIter __last)
60{
61 typename _Container::iterator __first_dest = __dest.begin();
62 typename _Container::iterator __last_dest = __dest.end();
63 while (__first_dest != __last_dest && __first != __last)
64 {
65 if (*__first_dest < *__first)
66 ++__first_dest;
67 else if (*__first < *__first_dest)
68 {
69 __dest.insert(__first_dest, *__first);
70 ++__first;
71 }
72 else // *__first_dest == *__first
73 {
74 ++__first_dest;
75 ++__first;
76 }
77 }
78 if (__first != __last)
79 std::copy(__first, __last, inserter(__dest, __last_dest));
80 return __dest;
81}
82
83template <class _Container, class _InputIter, class _Compare>
84_Container& set_assign_union(_Container& __dest,
85 _InputIter __first,
86 _InputIter __last,
87 _Compare __comp)
88{
89 typename _Container::iterator __first_dest = __dest.begin();
90 typename _Container::iterator __last_dest = __dest.end();
91 while (__first_dest != __last_dest && __first != __last)
92 {
93 if (__comp(*__first_dest, *__first))
94 ++__first_dest;
95 else if (__comp(*__first, *__first_dest))
96 {
97 __dest.insert(__first_dest, *__first);
98 ++__first;
99 }
100 else // *__first_dest is equivalent to *__first
101 {
102 ++__first_dest;
103 ++__first;
104 }
105 }
106 if (__first != __last)
107 std::copy(__first, __last, inserter(__dest, __last_dest));
108 return __dest;
109}
110
111template <class _Container, class _InputIter>
112_Container& set_assign_difference(_Container& __dest,
113 _InputIter __first,
114 _InputIter __last)
115{
116 typename _Container::iterator __first_dest = __dest.begin();
117 typename _Container::iterator __last_dest = __dest.end();
118 while (__first_dest != __last_dest && __first != __last)
119 {
120 if (*__first_dest < *__first)
121 ++__first_dest;
122 else if (*__first < *__first_dest)
123 ++__first;
124 else // *__first_dest == *__first
125 {
126 __dest.erase(__first_dest++);
127 ++__first;
128 }
129 }
130 return __dest;
131}
132
133template <class _Container, class _InputIter, class _Compare>
134_Container& set_assign_difference(_Container& __dest,
135 _InputIter __first,
136 _InputIter __last,
137 _Compare __comp)
138{
139 typename _Container::iterator __first_dest = __dest.begin();
140 typename _Container::iterator __last_dest = __dest.end();
141 while (__first_dest != __last_dest && __first != __last)
142 {
143 if (__comp(*__first_dest, *__first))
144 ++__first_dest;
145 else if (__comp(*__first, *__first_dest))
146 ++__first;
147 else // *__first_dest is equivalent to *__first
148 {
149 __dest.erase(__first_dest++);
150 ++__first;
151 }
152 }
153 return __dest;
154}
155
156} // namespace memory
157} // namespace qx
158
159#endif // _SET_ASSIGN_H
160#endif // _QX_USE_MEM_LEAK_DETECTION
161#endif // _QX_MODE_RELEASE
162#endif // QT_NO_DEBUG
_Container & set_assign_union(_Container &__dest, _InputIter __first, _InputIter __last)
Definition set_assign.h:57
_Container & set_assign_difference(_Container &__dest, _InputIter __first, _InputIter __last)
Definition set_assign.h:112
Root namespace for all QxOrm library features.