libstdc++
predefined_ops.h
Go to the documentation of this file.
00001 // Default predicates for internal use -*- C++ -*-
00002 
00003 // Copyright (C) 2013-2016 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. @headername{algorithm}
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       _GLIBCXX14_CONSTEXPR
00041       bool
00042       operator()(_Iterator1 __it1, _Iterator2 __it2) const
00043       { return *__it1 < *__it2; }
00044   };
00045 
00046   _GLIBCXX14_CONSTEXPR
00047   inline _Iter_less_iter
00048   __iter_less_iter()
00049   { return _Iter_less_iter(); }
00050 
00051   struct _Iter_less_val
00052   {
00053     template<typename _Iterator, typename _Value>
00054       bool
00055       operator()(_Iterator __it, _Value& __val) const
00056       { return *__it < __val; }
00057   };
00058 
00059   inline _Iter_less_val
00060   __iter_less_val()
00061   { return _Iter_less_val(); }
00062 
00063   inline _Iter_less_val
00064   __iter_comp_val(_Iter_less_iter)
00065   { return _Iter_less_val(); }
00066 
00067   struct _Val_less_iter
00068   {
00069     template<typename _Value, typename _Iterator>
00070       bool
00071       operator()(_Value& __val, _Iterator __it) const
00072       { return __val < *__it; }
00073   };
00074 
00075   inline _Val_less_iter
00076   __val_less_iter()
00077   { return _Val_less_iter(); }
00078 
00079   inline _Val_less_iter
00080   __val_comp_iter(_Iter_less_iter)
00081   { return _Val_less_iter(); }
00082 
00083   struct _Iter_equal_to_iter
00084   {
00085     template<typename _Iterator1, typename _Iterator2>
00086       bool
00087       operator()(_Iterator1 __it1, _Iterator2 __it2) const
00088       { return *__it1 == *__it2; }
00089   };
00090 
00091   inline _Iter_equal_to_iter
00092   __iter_equal_to_iter()
00093   { return _Iter_equal_to_iter(); }
00094 
00095   struct _Iter_equal_to_val
00096   {
00097     template<typename _Iterator, typename _Value>
00098       bool
00099       operator()(_Iterator __it, _Value& __val) const
00100       { return *__it == __val; }
00101   };
00102 
00103   inline _Iter_equal_to_val
00104   __iter_equal_to_val()
00105   { return _Iter_equal_to_val(); }
00106 
00107   inline _Iter_equal_to_val
00108   __iter_comp_val(_Iter_equal_to_iter)
00109   { return _Iter_equal_to_val(); }
00110 
00111   template<typename _Compare>
00112     struct _Iter_comp_iter
00113     {
00114       _Compare _M_comp;
00115 
00116       explicit _GLIBCXX14_CONSTEXPR
00117       _Iter_comp_iter(_Compare __comp)
00118         : _M_comp(__comp)
00119       { }
00120 
00121       template<typename _Iterator1, typename _Iterator2>
00122         _GLIBCXX14_CONSTEXPR
00123         bool
00124         operator()(_Iterator1 __it1, _Iterator2 __it2)
00125         { return bool(_M_comp(*__it1, *__it2)); }
00126     };
00127 
00128   template<typename _Compare>
00129     _GLIBCXX14_CONSTEXPR
00130     inline _Iter_comp_iter<_Compare>
00131     __iter_comp_iter(_Compare __comp)
00132     { return _Iter_comp_iter<_Compare>(__comp); }
00133 
00134   template<typename _Compare>
00135     struct _Iter_comp_val
00136     {
00137       _Compare _M_comp;
00138 
00139       explicit
00140       _Iter_comp_val(_Compare __comp)
00141         : _M_comp(__comp)
00142       { }
00143 
00144       template<typename _Iterator, typename _Value>
00145         bool
00146         operator()(_Iterator __it, _Value& __val)
00147         { return bool(_M_comp(*__it, __val)); }
00148     };
00149 
00150   template<typename _Compare>
00151    inline _Iter_comp_val<_Compare>
00152     __iter_comp_val(_Compare __comp)
00153     { return _Iter_comp_val<_Compare>(__comp); }
00154 
00155   template<typename _Compare>
00156     inline _Iter_comp_val<_Compare>
00157     __iter_comp_val(_Iter_comp_iter<_Compare> __comp)
00158     { return _Iter_comp_val<_Compare>(__comp._M_comp); }
00159 
00160   template<typename _Compare>
00161     struct _Val_comp_iter
00162     {
00163       _Compare _M_comp;
00164 
00165       explicit
00166       _Val_comp_iter(_Compare __comp)
00167         : _M_comp(__comp)
00168       { }
00169 
00170       template<typename _Value, typename _Iterator>
00171         bool
00172         operator()(_Value& __val, _Iterator __it)
00173         { return bool(_M_comp(__val, *__it)); }
00174     };
00175 
00176   template<typename _Compare>
00177     inline _Val_comp_iter<_Compare>
00178     __val_comp_iter(_Compare __comp)
00179     { return _Val_comp_iter<_Compare>(__comp); }
00180 
00181   template<typename _Compare>
00182     inline _Val_comp_iter<_Compare>
00183     __val_comp_iter(_Iter_comp_iter<_Compare> __comp)
00184     { return _Val_comp_iter<_Compare>(__comp._M_comp); }
00185 
00186   template<typename _Value>
00187     struct _Iter_equals_val
00188     {
00189       _Value& _M_value;
00190 
00191       explicit
00192       _Iter_equals_val(_Value& __value)
00193         : _M_value(__value)
00194       { }
00195 
00196       template<typename _Iterator>
00197         bool
00198         operator()(_Iterator __it)
00199         { return *__it == _M_value; }
00200     };
00201 
00202   template<typename _Value>
00203     inline _Iter_equals_val<_Value>
00204     __iter_equals_val(_Value& __val)
00205     { return _Iter_equals_val<_Value>(__val); }
00206 
00207   template<typename _Iterator1>
00208     struct _Iter_equals_iter
00209     {
00210       _Iterator1 _M_it1;
00211 
00212       explicit
00213       _Iter_equals_iter(_Iterator1 __it1)
00214         : _M_it1(__it1)
00215       { }
00216 
00217       template<typename _Iterator2>
00218         bool
00219         operator()(_Iterator2 __it2)
00220         { return *__it2 == *_M_it1; }
00221     };
00222 
00223   template<typename _Iterator>
00224     inline _Iter_equals_iter<_Iterator>
00225     __iter_comp_iter(_Iter_equal_to_iter, _Iterator __it)
00226     { return _Iter_equals_iter<_Iterator>(__it); }
00227 
00228   template<typename _Predicate>
00229     struct _Iter_pred
00230     {
00231       _Predicate _M_pred;
00232 
00233       explicit
00234       _Iter_pred(_Predicate __pred)
00235         : _M_pred(__pred)
00236       { }
00237 
00238       template<typename _Iterator>
00239         bool
00240         operator()(_Iterator __it)
00241         { return bool(_M_pred(*__it)); }
00242     };
00243 
00244   template<typename _Predicate>
00245     inline _Iter_pred<_Predicate>
00246     __pred_iter(_Predicate __pred)
00247     { return _Iter_pred<_Predicate>(__pred); }
00248 
00249   template<typename _Compare, typename _Value>
00250     struct _Iter_comp_to_val
00251     {
00252       _Compare _M_comp;
00253       _Value& _M_value;
00254 
00255       _Iter_comp_to_val(_Compare __comp, _Value& __value)
00256         : _M_comp(__comp), _M_value(__value)
00257       { }
00258 
00259       template<typename _Iterator>
00260         bool
00261         operator()(_Iterator __it)
00262         { return bool(_M_comp(*__it, _M_value)); }
00263     };
00264 
00265   template<typename _Compare, typename _Value>
00266     _Iter_comp_to_val<_Compare, _Value>
00267     __iter_comp_val(_Compare __comp, _Value &__val)
00268     { return _Iter_comp_to_val<_Compare, _Value>(__comp, __val); }
00269 
00270   template<typename _Compare, typename _Iterator1>
00271     struct _Iter_comp_to_iter
00272     {
00273       _Compare _M_comp;
00274       _Iterator1 _M_it1;
00275 
00276       _Iter_comp_to_iter(_Compare __comp, _Iterator1 __it1)
00277         : _M_comp(__comp), _M_it1(__it1)
00278       { }
00279 
00280       template<typename _Iterator2>
00281         bool
00282         operator()(_Iterator2 __it2)
00283         { return bool(_M_comp(*__it2, *_M_it1)); }
00284     };
00285 
00286   template<typename _Compare, typename _Iterator>
00287     inline _Iter_comp_to_iter<_Compare, _Iterator>
00288     __iter_comp_iter(_Iter_comp_iter<_Compare> __comp, _Iterator __it)
00289     { return _Iter_comp_to_iter<_Compare, _Iterator>(__comp._M_comp, __it); }
00290 
00291   template<typename _Predicate>
00292     struct _Iter_negate
00293     {
00294       _Predicate _M_pred;
00295 
00296       explicit
00297       _Iter_negate(_Predicate __pred)
00298         : _M_pred(__pred)
00299       { }
00300 
00301       template<typename _Iterator>
00302         bool
00303         operator()(_Iterator __it)
00304         { return !bool(_M_pred(*__it)); }
00305     };
00306 
00307   template<typename _Predicate>
00308     inline _Iter_negate<_Predicate>
00309     __negate(_Iter_pred<_Predicate> __pred)
00310     { return _Iter_negate<_Predicate>(__pred._M_pred); }
00311 
00312 } // namespace __ops
00313 } // namespace __gnu_cxx
00314 
00315 #endif