libstdc++
predefined_ops.h
Go to the documentation of this file.
00001 // Default predicates for internal use -*- C++ -*-
00002 
00003 // Copyright (C) 2013-2014 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file predefined_ops.h
00026  *  This is an internal header file, included by other library headers.
00027  *  You should not attempt to use it directly.
00028  */
00029 
00030 #ifndef _GLIBCXX_PREDEFINED_OPS_H
00031 #define _GLIBCXX_PREDEFINED_OPS_H   1
00032 
00033 namespace __gnu_cxx
00034 {
00035 namespace __ops
00036 {
00037   struct _Iter_less_iter
00038   {
00039     template<typename _Iterator1, typename _Iterator2>
00040       bool
00041       operator()(_Iterator1 __it1, _Iterator2 __it2) const
00042       { return *__it1 < *__it2; }
00043   };
00044 
00045   inline _Iter_less_iter
00046   __iter_less_iter()
00047   { return _Iter_less_iter(); }
00048 
00049   struct _Iter_less_val
00050   {
00051     template<typename _Iterator, typename _Value>
00052       bool
00053       operator()(_Iterator __it, _Value& __val) const
00054       { return *__it < __val; }
00055     };
00056 
00057   inline _Iter_less_val
00058   __iter_less_val()
00059   { return _Iter_less_val(); }
00060 
00061   inline _Iter_less_val
00062   __iter_comp_val(_Iter_less_iter)
00063   { return _Iter_less_val(); }
00064 
00065   struct _Val_less_iter
00066   {
00067     template<typename _Value, typename _Iterator>
00068       bool
00069       operator()(_Value& __val, _Iterator __it) const
00070       { return __val < *__it; }
00071     };
00072 
00073   inline _Val_less_iter
00074   __val_less_iter()
00075   { return _Val_less_iter(); }
00076 
00077   inline _Val_less_iter
00078   __val_comp_iter(_Iter_less_iter)
00079   { return _Val_less_iter(); }
00080 
00081   struct _Iter_equal_to_iter
00082   {
00083     template<typename _Iterator1, typename _Iterator2>
00084       bool
00085       operator()(_Iterator1 __it1, _Iterator2 __it2) const
00086       { return *__it1 == *__it2; }
00087     };
00088 
00089   inline _Iter_equal_to_iter
00090   __iter_equal_to_iter()
00091   { return _Iter_equal_to_iter(); }
00092 
00093   struct _Iter_equal_to_val
00094   {
00095     template<typename _Iterator, typename _Value>
00096       bool
00097       operator()(_Iterator __it, _Value& __val) const
00098       { return *__it == __val; }
00099     };
00100 
00101   inline _Iter_equal_to_val
00102   __iter_equal_to_val()
00103   { return _Iter_equal_to_val(); }
00104 
00105   inline _Iter_equal_to_val
00106   __iter_comp_val(_Iter_equal_to_iter)
00107   { return _Iter_equal_to_val(); }
00108 
00109   template<typename _Compare>
00110     struct _Iter_comp_iter
00111     {
00112       _Compare _M_comp;
00113 
00114       _Iter_comp_iter(_Compare __comp)
00115     : _M_comp(__comp)
00116       { }
00117 
00118       template<typename _Iterator1, typename _Iterator2>
00119         bool
00120         operator()(_Iterator1 __it1, _Iterator2 __it2)
00121         { return bool(_M_comp(*__it1, *__it2)); }
00122     };
00123 
00124   template<typename _Compare>
00125     inline _Iter_comp_iter<_Compare>
00126     __iter_comp_iter(_Compare __comp)
00127     { return _Iter_comp_iter<_Compare>(__comp); }
00128 
00129   template<typename _Compare>
00130     struct _Iter_comp_val
00131     {
00132       _Compare _M_comp;
00133 
00134       _Iter_comp_val(_Compare __comp)
00135     : _M_comp(__comp)
00136       { }
00137 
00138       template<typename _Iterator, typename _Value>
00139     bool
00140     operator()(_Iterator __it, _Value& __val)
00141     { return bool(_M_comp(*__it, __val)); }
00142     };
00143 
00144   template<typename _Compare>
00145    inline _Iter_comp_val<_Compare>
00146     __iter_comp_val(_Compare __comp)
00147     { return _Iter_comp_val<_Compare>(__comp); }
00148 
00149   template<typename _Compare>
00150     inline _Iter_comp_val<_Compare>
00151     __iter_comp_val(_Iter_comp_iter<_Compare> __comp)
00152     { return _Iter_comp_val<_Compare>(__comp._M_comp); }
00153 
00154   template<typename _Compare>
00155     struct _Val_comp_iter
00156     {
00157       _Compare _M_comp;
00158 
00159       _Val_comp_iter(_Compare __comp)
00160     : _M_comp(__comp)
00161       { }
00162 
00163       template<typename _Value, typename _Iterator>
00164     bool
00165     operator()(_Value& __val, _Iterator __it)
00166     { return bool(_M_comp(__val, *__it)); }
00167     };
00168 
00169   template<typename _Compare>
00170     inline _Val_comp_iter<_Compare>
00171     __val_comp_iter(_Compare __comp)
00172     { return _Val_comp_iter<_Compare>(__comp); }
00173 
00174   template<typename _Compare>
00175     inline _Val_comp_iter<_Compare>
00176     __val_comp_iter(_Iter_comp_iter<_Compare> __comp)
00177     { return _Val_comp_iter<_Compare>(__comp._M_comp); }
00178 
00179   template<typename _Value>
00180     struct _Iter_equals_val
00181     {
00182       _Value& _M_value;
00183 
00184       _Iter_equals_val(_Value& __value)
00185     : _M_value(__value)
00186       { }
00187 
00188       template<typename _Iterator>
00189     bool
00190     operator()(_Iterator __it)
00191     { return *__it == _M_value; }
00192     };
00193 
00194   template<typename _Value>
00195     inline _Iter_equals_val<_Value>
00196     __iter_equals_val(_Value& __val)
00197     { return _Iter_equals_val<_Value>(__val); }
00198 
00199   template<typename _Iterator1>
00200     struct _Iter_equals_iter
00201     {
00202       typename std::iterator_traits<_Iterator1>::reference _M_ref;
00203 
00204       _Iter_equals_iter(_Iterator1 __it1)
00205     : _M_ref(*__it1)
00206       { }
00207 
00208       template<typename _Iterator2>
00209     bool
00210     operator()(_Iterator2 __it2)
00211     { return *__it2 == _M_ref; }
00212     };
00213 
00214   template<typename _Iterator>
00215     inline _Iter_equals_iter<_Iterator>
00216     __iter_comp_iter(_Iter_equal_to_iter, _Iterator __it)
00217     { return _Iter_equals_iter<_Iterator>(__it); }
00218 
00219   template<typename _Predicate>
00220     struct _Iter_pred
00221     {
00222       _Predicate _M_pred;
00223 
00224       _Iter_pred(_Predicate __pred)
00225     : _M_pred(__pred)
00226       { }
00227 
00228       template<typename _Iterator>
00229     bool
00230     operator()(_Iterator __it)
00231     { return bool(_M_pred(*__it)); }
00232     };
00233 
00234   template<typename _Predicate>
00235     inline _Iter_pred<_Predicate>
00236     __pred_iter(_Predicate __pred)
00237     { return _Iter_pred<_Predicate>(__pred); }
00238 
00239   template<typename _Compare, typename _Value>
00240     struct _Iter_comp_to_val
00241     {
00242       _Compare _M_comp;
00243       _Value& _M_value;
00244 
00245       _Iter_comp_to_val(_Compare __comp, _Value& __value)
00246     : _M_comp(__comp), _M_value(__value)
00247       { }
00248 
00249       template<typename _Iterator>
00250     bool
00251     operator()(_Iterator __it)
00252     { return bool(_M_comp(*__it, _M_value)); }
00253     };
00254 
00255   template<typename _Compare, typename _Value>
00256     _Iter_comp_to_val<_Compare, _Value>
00257     __iter_comp_val(_Compare __comp, _Value &__val)
00258     { return _Iter_comp_to_val<_Compare, _Value>(__comp, __val); }
00259 
00260   template<typename _Compare, typename _Iterator1>
00261     struct _Iter_comp_to_iter
00262     {
00263       _Compare _M_comp;
00264       typename std::iterator_traits<_Iterator1>::reference _M_ref;
00265 
00266       _Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
00267     : _M_comp(__comp), _M_ref(*__it1)
00268       { }
00269 
00270       template<typename _Iterator2>
00271     bool
00272     operator()(_Iterator2 __it2)
00273     { return bool(_M_comp(*__it2, _M_ref)); }
00274     };
00275 
00276   template<typename _Compare, typename _Iterator>
00277     inline _Iter_comp_to_iter<_Compare, _Iterator>
00278     __iter_comp_iter(_Iter_comp_iter<_Compare> __comp, _Iterator __it)
00279     { return _Iter_comp_to_iter<_Compare, _Iterator>(__comp._M_comp, __it); }
00280 
00281   template<typename _Predicate>
00282     struct _Iter_negate
00283     {
00284       _Predicate _M_pred;
00285 
00286       _Iter_negate(_Predicate __pred)
00287     : _M_pred(__pred)
00288       { }
00289 
00290       template<typename _Iterator>
00291     bool
00292     operator()(_Iterator __it)
00293     { return !bool(_M_pred(*__it)); }
00294     };
00295 
00296   template<typename _Predicate>
00297     inline _Iter_negate<_Predicate>
00298     __negate(_Iter_pred<_Predicate> __pred)
00299     { return _Iter_negate<_Predicate>(__pred._M_pred); }
00300 
00301 } // namespace __ops
00302 } // namespace __gnu_cxx
00303 
00304 #endif