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
00037 #ifndef NVWA_SET_ASSIGN_H
00038 #define NVWA_SET_ASSIGN_H
00039
00040 #include <algorithm>
00041 #include "_nvwa.h"
00042
00043 NVWA_NAMESPACE_BEGIN
00044
00045 template <class _Container, class _InputIter>
00046 _Container& set_assign_union(_Container& dest,
00047 _InputIter first,
00048 _InputIter last)
00049 {
00050 typename _Container::iterator first_dest = dest.begin();
00051 typename _Container::iterator last_dest = dest.end();
00052 while (first_dest != last_dest && first != last)
00053 {
00054 if (*first_dest < *first)
00055 ++first_dest;
00056 else if (*first < *first_dest)
00057 {
00058 dest.insert(first_dest, *first);
00059 ++first;
00060 }
00061 else
00062 {
00063 ++first_dest;
00064 ++first;
00065 }
00066 }
00067 if (first != last)
00068 std::copy(first, last, inserter(dest, last_dest));
00069 return dest;
00070 }
00071
00072 template <class _Container, class _InputIter, class _Compare>
00073 _Container& set_assign_union(_Container& dest,
00074 _InputIter first,
00075 _InputIter last,
00076 _Compare comp)
00077 {
00078 typename _Container::iterator first_dest = dest.begin();
00079 typename _Container::iterator last_dest = dest.end();
00080 while (first_dest != last_dest && first != last)
00081 {
00082 if (comp(*first_dest, *first))
00083 ++first_dest;
00084 else if (comp(*first, *first_dest))
00085 {
00086 dest.insert(first_dest, *first);
00087 ++first;
00088 }
00089 else
00090 {
00091 ++first_dest;
00092 ++first;
00093 }
00094 }
00095 if (first != last)
00096 std::copy(first, last, inserter(dest, last_dest));
00097 return dest;
00098 }
00099
00100 template <class _Container, class _InputIter>
00101 _Container& set_assign_difference(_Container& dest,
00102 _InputIter first,
00103 _InputIter last)
00104 {
00105 typename _Container::iterator first_dest = dest.begin();
00106 typename _Container::iterator last_dest = dest.end();
00107 while (first_dest != last_dest && first != last)
00108 {
00109 if (*first_dest < *first)
00110 ++first_dest;
00111 else if (*first < *first_dest)
00112 ++first;
00113 else
00114 {
00115 dest.erase(first_dest++);
00116 ++first;
00117 }
00118 }
00119 return dest;
00120 }
00121
00122 template <class _Container, class _InputIter, class _Compare>
00123 _Container& set_assign_difference(_Container& dest,
00124 _InputIter first,
00125 _InputIter last,
00126 _Compare comp)
00127 {
00128 typename _Container::iterator first_dest = dest.begin();
00129 typename _Container::iterator last_dest = dest.end();
00130 while (first_dest != last_dest && first != last)
00131 {
00132 if (comp(*first_dest, *first))
00133 ++first_dest;
00134 else if (comp(*first, *first_dest))
00135 ++first;
00136 else
00137 {
00138 dest.erase(first_dest++);
00139 ++first;
00140 }
00141 }
00142 return dest;
00143 }
00144
00145 NVWA_NAMESPACE_END
00146
00147 #endif // NVWA_SET_ASSIGN_H