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