stlab.adobe.com Adobe Systems Incorporated

is_member.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2008 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_FUNCTIONAL_IS_MEMBER_HPP
00010 #define ADOBE_FUNCTIONAL_IS_MEMBER_HPP
00011 
00012 #include <adobe/config.hpp>
00013 
00014 #include <boost/iterator/iterator_traits.hpp>
00015 #include <boost/range/begin.hpp>
00016 #include <boost/range/const_iterator.hpp>
00017 #include <boost/range/end.hpp>
00018 
00019 #include <adobe/algorithm/binary_search.hpp>
00020 #include <adobe/functional/operator.hpp>
00021 
00022 /*************************************************************************************************/
00023 
00024 namespace adobe {
00025 
00026 /*************************************************************************************************/
00027 
00032 template <typename I,           // I ForwardIterator
00033           typename O = less>    // O modles StrictWeakOrdering
00034 struct is_member
00035 {
00036     typedef bool result_type;
00037 
00038     is_member(I f, I l, O o = O()) : first(f), last(l), compare(o) { }
00039 
00040     bool operator()(const typename boost::iterator_value<I>::type& x) const
00041     { return binary_search(first, last, x, compare) != last; }
00042 
00043     I first;
00044     I last;
00045     O compare;
00046 };
00047 
00048 template <typename I> // I models ForwardIterator
00049 is_member<I, less> make_is_member(I f, I l) { return is_member<I, less>(f, l); }
00050 
00051 template <typename I, // I models ForwardIterator
00052           typename O> // O modles StrictWeakOrdering
00053 is_member<I, O> make_is_member(I f, I l, O o) { return is_member<I, O>(f, l, o); }
00054 
00055 template <typename I> // I models ForwardRange
00056 is_member<typename boost::range_const_iterator<I>::type, less> make_is_member(const I& r)
00057 { return make_is_member(begin(r), end(r)); }
00058 
00059 template <typename I, // I models ForwardRange
00060           typename O> // O modles StrictWeakOrdering
00061 is_member<typename boost::range_const_iterator<I>::type, O> make_is_member(const I& r, O o)
00062 { return make_is_member(begin(r), end(r), o); }
00063 
00065 
00066 /*************************************************************************************************/
00067 
00068 } // namespace adobe
00069 
00070 /*************************************************************************************************/
00071 
00072 #endif
00073 
00074 /*************************************************************************************************/

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