stlab.adobe.com Adobe Systems Incorporated

erase_if.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef ADOBE_ALGORITHM_ERASE_IF_HPP
00010 #define ADOBE_ALGORITHM_ERASE_IF_HPP
00011 
00012 #include <adobe/config.hpp>
00013 
00014 #include <cassert>
00015 
00016 #include <boost/range/begin.hpp>
00017 #include <boost/range/end.hpp>
00018 #include <boost/next_prior.hpp>
00019 
00020 #include <adobe/algorithm/remove.hpp>
00021 #include <adobe/algorithm/find.hpp>
00022 #include <adobe/container/storage.hpp>
00023 
00024 /*************************************************************************************************/
00025 
00026 namespace adobe {
00027 
00028 /*************************************************************************************************/
00042 /*************************************************************************************************/
00043 
00044 namespace implementation {
00045 
00046 
00047 template <typename T> // T models Container
00048 typename T::iterator erase(T& x, typename T::iterator f, typename T::iterator l, block_tag)
00049 { return x.erase(f, l); }
00050 
00051 template <typename T> // T models Container
00052 typename T::iterator erase(T& x, typename T::iterator f, typename T::iterator l, node_tag)
00053 { x.erase(f, l); return l; }
00054 
00055 } // implementation
00056 
00057 /*************************************************************************************************/
00058 
00062 template <typename T> // T models Container
00063 typename T::iterator erase(T& x, typename T::iterator f, typename T::iterator l)
00064 {
00065     return implementation::erase(x, f, l, typename storage_category<T>::type());
00066 }
00067 
00068 /*************************************************************************************************/
00069 
00073 template <  typename T, // T models Container
00074             typename R> // R models Range(iterator(T), iterator(T))
00075 typename T::iterator erase(T& x, const R& r)
00076 {
00077     return erase(x, boost::begin(r), boost::end(r));
00078 }
00079 
00084 template <typename T> // T models Container
00085 typename T::iterator erase(T& x, typename T::iterator f)
00086 {
00087     assert(f != end(x) && "FATAL (sparent) : Attempt to erase the end of a container.");
00088     return erase(x, f, boost::next(f));
00089 }
00090 
00091 /*************************************************************************************************/
00092 
00093 namespace implementation {
00094 
00095 template <  typename T, // T models Container
00096             typename P> // P models UnaryPredicate
00097 void erase_if(T& x, typename T::iterator f, typename T::iterator l, P p, block_tag)
00098 { x.erase(adobe::remove_if(f, l, p), l); }
00099 
00100 template <  typename T, // T models Container
00101             typename P> // P models UnaryPredicate
00102 void erase_if(T& x, typename T::iterator f, typename T::iterator l, P p, node_tag)
00103 {
00104     while (f != l) {
00105         f = adobe::erase(x, find_range_if(f, l, p));
00106     }
00107 }
00108 
00109 } // implementation
00110 
00111 /*************************************************************************************************/
00112 
00117 template <  typename T, // T models Container
00118             typename P> // P models UnaryPredicate
00119 void erase_if(T& x, typename T::iterator f, typename T::iterator l, P p)
00120 {
00121     implementation::erase_if(x, f, l, p, typename storage_category<T>::type());
00122 }
00123 
00128 template <  typename T, // T models Container
00129             typename P> // P models UnaryPredicate
00130 void erase_if(T& x, P p)
00131 {
00132     erase_if(x, boost::begin(x), boost::end(x), p);
00133 }
00134 
00135 /*************************************************************************************************/
00136 
00137 } // namespace adobe
00138 
00139 /*************************************************************************************************/
00140 
00141 #endif
00142 
00143 /*************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google