filter.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_FILTER_HPP 00010 #define ADOBE_ALGORITHM_FILTER_HPP 00011 00012 #include <adobe/config.hpp> 00013 00014 #include <boost/range/begin.hpp> 00015 #include <boost/range/end.hpp> 00016 #include <boost/bind.hpp> 00017 00018 #include <algorithm> 00019 00020 /*************************************************************************************************/ 00021 00022 namespace adobe { 00023 00024 /*************************************************************************************************/ 00050 /*************************************************************************************************/ 00051 #ifndef ADOBE_NO_DOCUMENTATION 00052 namespace implementation { 00053 00054 /*************************************************************************************************/ 00055 00056 template <typename I, // I models InputIterator 00057 typename O, // O models OutputIterator 00058 typename F> // F is a function type of the form O F()(value_type(I), O) 00059 O filter(I first, I last, O result, F op) 00060 { 00061 while (first != last) 00062 { 00063 result = op(*first, result); 00064 ++first; 00065 } 00066 return result; 00067 } 00068 00069 /*************************************************************************************************/ 00070 00071 } // namespace implementation 00072 #endif 00073 /*************************************************************************************************/ 00079 template <typename I, // I models InputIterator 00080 typename O, // O models OutputIterator 00081 typename F> // F is a function type of the form O F()(value_type(I), O) 00082 inline O filter(I first, I last, O result, F op) 00083 { 00084 return implementation::filter(first, last, result, boost::bind<O>(op, _1, _2)); 00085 } 00086 00092 template <typename I, // I models InputRange 00093 typename O, // O models OutputIterator 00094 typename F> // F is a function type of the form O F()(value_type(I), O) 00095 O filter(I& source, O result, F op) 00096 { 00097 return adobe::filter(boost::begin(source), boost::end(source), result, op); 00098 } 00099 00105 template <typename I, // I models InputRange 00106 typename O, // O models OutputIterator 00107 typename F> // F is a function type of the form O F()(value_type(I), O) 00108 O filter(const I& source, O result, F op) 00109 { 00110 return adobe::filter(boost::begin(source), boost::end(source), result, op); 00111 } 00112 00113 /*************************************************************************************************/ 00114 00115 } // namespace adobe 00116 00117 /*************************************************************************************************/ 00118 00119 #endif 00120 00121 /*************************************************************************************************/ |