• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2015-2016.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // See http://www.boost.org/libs/move for documentation.
9 //
10 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_MOVE_ALGO_PREDICATE_HPP
12 #define BOOST_MOVE_ALGO_PREDICATE_HPP
13 
14 #include <boost/move/algo/move.hpp>
15 #include <boost/move/adl_move_swap.hpp>
16 #include <boost/move/algo/detail/basic_op.hpp>
17 #include <boost/move/detail/iterator_traits.hpp>
18 #include <boost/move/detail/destruct_n.hpp>
19 #include <boost/assert.hpp>
20 
21 namespace boost {
22 namespace movelib {
23 
24 template<class Comp>
25 struct antistable
26 {
antistableboost::movelib::antistable27    explicit antistable(Comp &comp)
28       : m_comp(comp)
29    {}
30 
antistableboost::movelib::antistable31    antistable(const antistable & other)
32       : m_comp(other.m_comp)
33    {}
34 
35    template<class U, class V>
operator ()boost::movelib::antistable36    bool operator()(const U &u, const V & v)
37    {  return !m_comp(v, u);  }
38 
getboost::movelib::antistable39    const Comp &get() const
40    {  return m_comp; }
41 
42    private:
43    antistable & operator=(const antistable &);
44    Comp &m_comp;
45 };
46 
47 template<class Comp>
unantistable(Comp comp)48 Comp unantistable(Comp comp)
49 {   return comp;  }
50 
51 template<class Comp>
unantistable(antistable<Comp> comp)52 Comp unantistable(antistable<Comp> comp)
53 {   return comp.get();  }
54 
55 template <class Comp>
56 class negate
57 {
58    public:
negate()59    negate()
60    {}
61 
negate(Comp comp)62    explicit negate(Comp comp)
63       : m_comp(comp)
64    {}
65 
66    template <class T1, class T2>
operator ()(const T1 & l,const T2 & r)67    bool operator()(const T1& l, const T2& r)
68    {
69       return !m_comp(l, r);
70    }
71 
72    private:
73    Comp m_comp;
74 };
75 
76 
77 template <class Comp>
78 class inverse
79 {
80    public:
inverse()81    inverse()
82    {}
83 
inverse(Comp comp)84    explicit inverse(Comp comp)
85       : m_comp(comp)
86    {}
87 
88    template <class T1, class T2>
operator ()(const T1 & l,const T2 & r)89    bool operator()(const T1& l, const T2& r)
90    {
91       return m_comp(r, l);
92    }
93 
94    private:
95    Comp m_comp;
96 };
97 
98 }  //namespace movelib {
99 }  //namespace boost {
100 
101 #endif   //#define BOOST_MOVE_ALGO_PREDICATE_HPP
102