| QxOrm 1.5.0 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

set_assign.h
Go to the documentation of this file.

    00001 // -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
    00002 // vim:tabstop=4:shiftwidth=4:expandtab:
    00003
    00004 /*
    00005  * Copyright (C) 2004-2008 Wu Yongwei <adah at users dot sourceforge dot net>
    00006  *
    00007  * This software is provided 'as-is', without any express or implied
    00008  * warranty.  In no event will the authors be held liable for any
    00009  * damages arising from the use of this software.
    00010  *
    00011  * Permission is granted to anyone to use this software for any purpose,
    00012  * including commercial applications, and to alter it and redistribute
    00013  * it freely, subject to the following restrictions:
    00014  *
    00015  * 1. The origin of this software must not be misrepresented; you must
    00016  *    not claim that you wrote the original software.  If you use this
    00017  *    software in a product, an acknowledgement in the product
    00018  *    documentation would be appreciated but is not required.
    00019  * 2. Altered source versions must be plainly marked as such, and must
    00020  *    not be misrepresented as being the original software.
    00021  * 3. This notice may not be removed or altered from any source
    00022  *    distribution.
    00023  *
    00024  * This file is part of Stones of Nvwa:
    00025  *      http://sourceforge.net/projects/nvwa
    00026  *
    00027  */
    00028
    00040 #ifndef QT_NO_DEBUG
    00041 #ifndef _QX_MODE_RELEASE
    00042 #if _QX_USE_MEM_LEAK_DETECTION
    00043
    00044 #ifndef _SET_ASSIGN_H
    00045 #define _SET_ASSIGN_H
    00046
    00047 #ifdef _MSC_VER
    00048 #pragma once
    00049 #endif
    00050
    00051 #include <algorithm>
    00052
    00053 namespace qx {
    00054 namespace memory {
    00055
    00056 template <class _Container, class _InputIter>
    00057 _Container& set_assign_union(_Container& __dest,
    00058                              _InputIter __first,
    00059                              _InputIter __last)
    00060 {
    00061     typename _Container::iterator __first_dest = __dest.begin();
    00062     typename _Container::iterator  __last_dest = __dest.end();
    00063     while (__first_dest != __last_dest && __first != __last)
    00064     {
    00065         if (*__first_dest < *__first)
    00066             ++__first_dest;
    00067         else if (*__first < *__first_dest)
    00068         {
    00069             __dest.insert(__first_dest, *__first);
    00070             ++__first;
    00071         }
    00072         else    // *__first_dest == *__first
    00073         {
    00074             ++__first_dest;
    00075             ++__first;
    00076         }
    00077     }
    00078     if (__first != __last)
    00079         std::copy(__first, __last, inserter(__dest, __last_dest));
    00080     return __dest;
    00081 }
    00082
    00083 template <class _Container, class _InputIter, class _Compare>
    00084 _Container& set_assign_union(_Container& __dest,
    00085                              _InputIter __first,
    00086                              _InputIter __last,
    00087                              _Compare __comp)
    00088 {
    00089     typename _Container::iterator __first_dest = __dest.begin();
    00090     typename _Container::iterator  __last_dest = __dest.end();
    00091     while (__first_dest != __last_dest && __first != __last)
    00092     {
    00093         if (__comp(*__first_dest, *__first))
    00094             ++__first_dest;
    00095         else if (__comp(*__first, *__first_dest))
    00096         {
    00097             __dest.insert(__first_dest, *__first);
    00098             ++__first;
    00099         }
    00100         else    // *__first_dest is equivalent to *__first
    00101         {
    00102             ++__first_dest;
    00103             ++__first;
    00104         }
    00105     }
    00106     if (__first != __last)
    00107         std::copy(__first, __last, inserter(__dest, __last_dest));
    00108     return __dest;
    00109 }
    00110
    00111 template <class _Container, class _InputIter>
    00112 _Container& set_assign_difference(_Container& __dest,
    00113                                   _InputIter __first,
    00114                                   _InputIter __last)
    00115 {
    00116     typename _Container::iterator __first_dest = __dest.begin();
    00117     typename _Container::iterator  __last_dest = __dest.end();
    00118     while (__first_dest != __last_dest && __first != __last)
    00119     {
    00120         if (*__first_dest < *__first)
    00121             ++__first_dest;
    00122         else if (*__first < *__first_dest)
    00123             ++__first;
    00124         else    // *__first_dest == *__first
    00125         {
    00126             __dest.erase(__first_dest++);
    00127             ++__first;
    00128         }
    00129     }
    00130     return __dest;
    00131 }
    00132
    00133 template <class _Container, class _InputIter, class _Compare>
    00134 _Container& set_assign_difference(_Container& __dest,
    00135                                   _InputIter __first,
    00136                                   _InputIter __last,
    00137                                   _Compare __comp)
    00138 {
    00139     typename _Container::iterator __first_dest = __dest.begin();
    00140     typename _Container::iterator  __last_dest = __dest.end();
    00141     while (__first_dest != __last_dest && __first != __last)
    00142     {
    00143         if (__comp(*__first_dest, *__first))
    00144             ++__first_dest;
    00145         else if (__comp(*__first, *__first_dest))
    00146             ++__first;
    00147         else    // *__first_dest is equivalent to *__first
    00148         {
    00149             __dest.erase(__first_dest++);
    00150             ++__first;
    00151         }
    00152     }
    00153     return __dest;
    00154 }
    00155
    00156 } // namespace memory
    00157 } // namespace qx
    00158
    00159 #endif // _SET_ASSIGN_H
    00160 #endif // _QX_USE_MEM_LEAK_DETECTION
    00161 #endif // _QX_MODE_RELEASE
    00162 #endif // QT_NO_DEBUG