00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00039 #ifndef _SET_ASSIGN_H
00040 #define _SET_ASSIGN_H
00041
00042 #include <algorithm>
00043
00044 template <class _Container, class _InputIter>
00045 _Container& set_assign_union(_Container& __dest,
00046 _InputIter __first,
00047 _InputIter __last)
00048 {
00049 typename _Container::iterator __first_dest = __dest.begin();
00050 typename _Container::iterator __last_dest = __dest.end();
00051 while (__first_dest != __last_dest && __first != __last)
00052 {
00053 if (*__first_dest < *__first)
00054 ++__first_dest;
00055 else if (*__first < *__first_dest)
00056 {
00057 __dest.insert(__first_dest, *__first);
00058 ++__first;
00059 }
00060 else
00061 {
00062 ++__first_dest;
00063 ++__first;
00064 }
00065 }
00066 if (__first != __last)
00067 std::copy(__first, __last, inserter(__dest, __last_dest));
00068 return __dest;
00069 }
00070
00071 template <class _Container, class _InputIter, class _Compare>
00072 _Container& set_assign_union(_Container& __dest,
00073 _InputIter __first,
00074 _InputIter __last,
00075 _Compare __comp)
00076 {
00077 typename _Container::iterator __first_dest = __dest.begin();
00078 typename _Container::iterator __last_dest = __dest.end();
00079 while (__first_dest != __last_dest && __first != __last)
00080 {
00081 if (__comp(*__first_dest, *__first))
00082 ++__first_dest;
00083 else if (__comp(*__first, *__first_dest))
00084 {
00085 __dest.insert(__first_dest, *__first);
00086 ++__first;
00087 }
00088 else
00089 {
00090 ++__first_dest;
00091 ++__first;
00092 }
00093 }
00094 if (__first != __last)
00095 std::copy(__first, __last, inserter(__dest, __last_dest));
00096 return __dest;
00097 }
00098
00099 template <class _Container, class _InputIter>
00100 _Container& set_assign_difference(_Container& __dest,
00101 _InputIter __first,
00102 _InputIter __last)
00103 {
00104 typename _Container::iterator __first_dest = __dest.begin();
00105 typename _Container::iterator __last_dest = __dest.end();
00106 while (__first_dest != __last_dest && __first != __last)
00107 {
00108 if (*__first_dest < *__first)
00109 ++__first_dest;
00110 else if (*__first < *__first_dest)
00111 ++__first;
00112 else
00113 {
00114 __dest.erase(__first_dest++);
00115 ++__first;
00116 }
00117 }
00118 return __dest;
00119 }
00120
00121 template <class _Container, class _InputIter, class _Compare>
00122 _Container& set_assign_difference(_Container& __dest,
00123 _InputIter __first,
00124 _InputIter __last,
00125 _Compare __comp)
00126 {
00127 typename _Container::iterator __first_dest = __dest.begin();
00128 typename _Container::iterator __last_dest = __dest.end();
00129 while (__first_dest != __last_dest && __first != __last)
00130 {
00131 if (__comp(*__first_dest, *__first))
00132 ++__first_dest;
00133 else if (__comp(*__first, *__first_dest))
00134 ++__first;
00135 else
00136 {
00137 __dest.erase(__first_dest++);
00138 ++__first;
00139 }
00140 }
00141 return __dest;
00142 }
00143
00144 #endif // _SET_ASSIGN_H