Home | History | Annotate | Download | only in bits
      1 // Default predicates for internal use -*- C++ -*-
      2 
      3 // Copyright (C) 2013-2014 Free Software Foundation, Inc.
      4 //
      5 // This file is part of the GNU ISO C++ Library.  This library is free
      6 // software; you can redistribute it and/or modify it under the
      7 // terms of the GNU General Public License as published by the
      8 // Free Software Foundation; either version 3, or (at your option)
      9 // any later version.
     10 
     11 // This library is distributed in the hope that it will be useful,
     12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 // GNU General Public License for more details.
     15 
     16 // Under Section 7 of GPL version 3, you are granted additional
     17 // permissions described in the GCC Runtime Library Exception, version
     18 // 3.1, as published by the Free Software Foundation.
     19 
     20 // You should have received a copy of the GNU General Public License and
     21 // a copy of the GCC Runtime Library Exception along with this program;
     22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     23 // <http://www.gnu.org/licenses/>.
     24 
     25 /** @file predefined_ops.h
     26  *  This is an internal header file, included by other library headers.
     27  *  You should not attempt to use it directly.
     28  */
     29 
     30 #ifndef _GLIBCXX_PREDEFINED_OPS_H
     31 #define _GLIBCXX_PREDEFINED_OPS_H	1
     32 
     33 namespace __gnu_cxx
     34 {
     35 namespace __ops
     36 {
     37   struct _Iter_less_iter
     38   {
     39     template<typename _Iterator1, typename _Iterator2>
     40       bool
     41       operator()(_Iterator1 __it1, _Iterator2 __it2) const
     42       { return *__it1 < *__it2; }
     43   };
     44 
     45   inline _Iter_less_iter
     46   __iter_less_iter()
     47   { return _Iter_less_iter(); }
     48 
     49   struct _Iter_less_val
     50   {
     51     template<typename _Iterator, typename _Value>
     52       bool
     53       operator()(_Iterator __it, _Value& __val) const
     54       { return *__it < __val; }
     55     };
     56 
     57   inline _Iter_less_val
     58   __iter_less_val()
     59   { return _Iter_less_val(); }
     60 
     61   inline _Iter_less_val
     62   __iter_comp_val(_Iter_less_iter)
     63   { return _Iter_less_val(); }
     64 
     65   struct _Val_less_iter
     66   {
     67     template<typename _Value, typename _Iterator>
     68       bool
     69       operator()(_Value& __val, _Iterator __it) const
     70       { return __val < *__it; }
     71     };
     72 
     73   inline _Val_less_iter
     74   __val_less_iter()
     75   { return _Val_less_iter(); }
     76 
     77   inline _Val_less_iter
     78   __val_comp_iter(_Iter_less_iter)
     79   { return _Val_less_iter(); }
     80 
     81   struct _Iter_equal_to_iter
     82   {
     83     template<typename _Iterator1, typename _Iterator2>
     84       bool
     85       operator()(_Iterator1 __it1, _Iterator2 __it2) const
     86       { return *__it1 == *__it2; }
     87     };
     88 
     89   inline _Iter_equal_to_iter
     90   __iter_equal_to_iter()
     91   { return _Iter_equal_to_iter(); }
     92 
     93   struct _Iter_equal_to_val
     94   {
     95     template<typename _Iterator, typename _Value>
     96       bool
     97       operator()(_Iterator __it, _Value& __val) const
     98       { return *__it == __val; }
     99     };
    100 
    101   inline _Iter_equal_to_val
    102   __iter_equal_to_val()
    103   { return _Iter_equal_to_val(); }
    104 
    105   inline _Iter_equal_to_val
    106   __iter_comp_val(_Iter_equal_to_iter)
    107   { return _Iter_equal_to_val(); }
    108 
    109   template<typename _Compare>
    110     struct _Iter_comp_iter
    111     {
    112       _Compare _M_comp;
    113 
    114       _Iter_comp_iter(_Compare __comp)
    115 	: _M_comp(__comp)
    116       { }
    117 
    118       template<typename _Iterator1, typename _Iterator2>
    119         bool
    120         operator()(_Iterator1 __it1, _Iterator2 __it2)
    121         { return bool(_M_comp(*__it1, *__it2)); }
    122     };
    123 
    124   template<typename _Compare>
    125     inline _Iter_comp_iter<_Compare>
    126     __iter_comp_iter(_Compare __comp)
    127     { return _Iter_comp_iter<_Compare>(__comp); }
    128 
    129   template<typename _Compare>
    130     struct _Iter_comp_val
    131     {
    132       _Compare _M_comp;
    133 
    134       _Iter_comp_val(_Compare __comp)
    135 	: _M_comp(__comp)
    136       { }
    137 
    138       template<typename _Iterator, typename _Value>
    139 	bool
    140 	operator()(_Iterator __it, _Value& __val)
    141 	{ return bool(_M_comp(*__it, __val)); }
    142     };
    143 
    144   template<typename _Compare>
    145    inline _Iter_comp_val<_Compare>
    146     __iter_comp_val(_Compare __comp)
    147     { return _Iter_comp_val<_Compare>(__comp); }
    148 
    149   template<typename _Compare>
    150     inline _Iter_comp_val<_Compare>
    151     __iter_comp_val(_Iter_comp_iter<_Compare> __comp)
    152     { return _Iter_comp_val<_Compare>(__comp._M_comp); }
    153 
    154   template<typename _Compare>
    155     struct _Val_comp_iter
    156     {
    157       _Compare _M_comp;
    158 
    159       _Val_comp_iter(_Compare __comp)
    160 	: _M_comp(__comp)
    161       { }
    162 
    163       template<typename _Value, typename _Iterator>
    164 	bool
    165 	operator()(_Value& __val, _Iterator __it)
    166 	{ return bool(_M_comp(__val, *__it)); }
    167     };
    168 
    169   template<typename _Compare>
    170     inline _Val_comp_iter<_Compare>
    171     __val_comp_iter(_Compare __comp)
    172     { return _Val_comp_iter<_Compare>(__comp); }
    173 
    174   template<typename _Compare>
    175     inline _Val_comp_iter<_Compare>
    176     __val_comp_iter(_Iter_comp_iter<_Compare> __comp)
    177     { return _Val_comp_iter<_Compare>(__comp._M_comp); }
    178 
    179   template<typename _Value>
    180     struct _Iter_equals_val
    181     {
    182       _Value& _M_value;
    183 
    184       _Iter_equals_val(_Value& __value)
    185 	: _M_value(__value)
    186       { }
    187 
    188       template<typename _Iterator>
    189 	bool
    190 	operator()(_Iterator __it)
    191 	{ return *__it == _M_value; }
    192     };
    193 
    194   template<typename _Value>
    195     inline _Iter_equals_val<_Value>
    196     __iter_equals_val(_Value& __val)
    197     { return _Iter_equals_val<_Value>(__val); }
    198 
    199   template<typename _Iterator1>
    200     struct _Iter_equals_iter
    201     {
    202       typename std::iterator_traits<_Iterator1>::reference _M_ref;
    203 
    204       _Iter_equals_iter(_Iterator1 __it1)
    205 	: _M_ref(*__it1)
    206       { }
    207 
    208       template<typename _Iterator2>
    209 	bool
    210 	operator()(_Iterator2 __it2)
    211 	{ return *__it2 == _M_ref; }
    212     };
    213 
    214   template<typename _Iterator>
    215     inline _Iter_equals_iter<_Iterator>
    216     __iter_comp_iter(_Iter_equal_to_iter, _Iterator __it)
    217     { return _Iter_equals_iter<_Iterator>(__it); }
    218 
    219   template<typename _Predicate>
    220     struct _Iter_pred
    221     {
    222       _Predicate _M_pred;
    223 
    224       _Iter_pred(_Predicate __pred)
    225 	: _M_pred(__pred)
    226       { }
    227 
    228       template<typename _Iterator>
    229 	bool
    230 	operator()(_Iterator __it)
    231 	{ return bool(_M_pred(*__it)); }
    232     };
    233 
    234   template<typename _Predicate>
    235     inline _Iter_pred<_Predicate>
    236     __pred_iter(_Predicate __pred)
    237     { return _Iter_pred<_Predicate>(__pred); }
    238 
    239   template<typename _Compare, typename _Value>
    240     struct _Iter_comp_to_val
    241     {
    242       _Compare _M_comp;
    243       _Value& _M_value;
    244 
    245       _Iter_comp_to_val(_Compare __comp, _Value& __value)
    246 	: _M_comp(__comp), _M_value(__value)
    247       { }
    248 
    249       template<typename _Iterator>
    250 	bool
    251 	operator()(_Iterator __it)
    252 	{ return bool(_M_comp(*__it, _M_value)); }
    253     };
    254 
    255   template<typename _Compare, typename _Value>
    256     _Iter_comp_to_val<_Compare, _Value>
    257     __iter_comp_val(_Compare __comp, _Value &__val)
    258     { return _Iter_comp_to_val<_Compare, _Value>(__comp, __val); }
    259 
    260   template<typename _Compare, typename _Iterator1>
    261     struct _Iter_comp_to_iter
    262     {
    263       _Compare _M_comp;
    264       typename std::iterator_traits<_Iterator1>::reference _M_ref;
    265 
    266       _Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
    267 	: _M_comp(__comp), _M_ref(*__it1)
    268       { }
    269 
    270       template<typename _Iterator2>
    271 	bool
    272 	operator()(_Iterator2 __it2)
    273 	{ return bool(_M_comp(*__it2, _M_ref)); }
    274     };
    275 
    276   template<typename _Compare, typename _Iterator>
    277     inline _Iter_comp_to_iter<_Compare, _Iterator>
    278     __iter_comp_iter(_Iter_comp_iter<_Compare> __comp, _Iterator __it)
    279     { return _Iter_comp_to_iter<_Compare, _Iterator>(__comp._M_comp, __it); }
    280 
    281   template<typename _Predicate>
    282     struct _Iter_negate
    283     {
    284       _Predicate _M_pred;
    285 
    286       _Iter_negate(_Predicate __pred)
    287 	: _M_pred(__pred)
    288       { }
    289 
    290       template<typename _Iterator>
    291 	bool
    292 	operator()(_Iterator __it)
    293 	{ return !bool(_M_pred(*__it)); }
    294     };
    295 
    296   template<typename _Predicate>
    297     inline _Iter_negate<_Predicate>
    298     __negate(_Iter_pred<_Predicate> __pred)
    299     { return _Iter_negate<_Predicate>(__pred._M_pred); }
    300 
    301 } // namespace __ops
    302 } // namespace __gnu_cxx
    303 
    304 #endif
    305