stlab.adobe.com Adobe Systems Incorporated
is_member.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2008 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_FUNCTIONAL_IS_MEMBER_HPP
10 #define ADOBE_FUNCTIONAL_IS_MEMBER_HPP
11 
12 #include <adobe/config.hpp>
13 
14 #include <boost/iterator/iterator_traits.hpp>
15 #include <boost/range/begin.hpp>
16 #include <boost/range/const_iterator.hpp>
17 #include <boost/range/end.hpp>
18 
21 
22 /*************************************************************************************************/
23 
24 namespace adobe {
25 
26 /*************************************************************************************************/
27 
32 template <typename I, // I ForwardIterator
33  typename O = less> // O modles StrictWeakOrdering
34 struct is_member
35 {
36  typedef bool result_type;
37 
38  is_member(I f, I l, O o = O()) : first(f), last(l), compare(o) { }
39 
40  bool operator()(const typename boost::iterator_value<I>::type& x) const
41  { return binary_search(first, last, x, compare) != last; }
42 
43  I first;
44  I last;
46 };
47 
48 template <typename I> // I models ForwardIterator
50 
51 template <typename I, // I models ForwardIterator
52  typename O> // O modles StrictWeakOrdering
53 is_member<I, O> make_is_member(I f, I l, O o) { return is_member<I, O>(f, l, o); }
54 
55 template <typename I> // I models ForwardRange
57 { return make_is_member(begin(r), end(r)); }
58 
59 template <typename I, // I models ForwardRange
60  typename O> // O modles StrictWeakOrdering
62 { return make_is_member(begin(r), end(r), o); }
63 
65 
66 /*************************************************************************************************/
67 
68 } // namespace adobe
69 
70 /*************************************************************************************************/
71 
72 #endif
73 
74 /*************************************************************************************************/
bool operator()(const typename boost::iterator_value< I >::type &x) const
Definition: is_member.hpp:40
is_member(I f, I l, O o=O())
Definition: is_member.hpp:38
I binary_search(I f, I l, const T &x, C c, P p)
is_member< I, less > make_is_member(I f, I l)
Definition: is_member.hpp:49

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