Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/c++/15/bits/boost_concept_check.h
1 // -*- C++ -*- 2 3 // Copyright (C) 2004-2025 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 // (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify, 26 // sell and distribute this software is granted provided this 27 // copyright notice appears in all copies. This software is provided 28 // "as is" without express or implied warranty, and with no claim as 29 // to its suitability for any purpose. 30 // 31 32 /** @file bits/boost_concept_check.h 33 * This is an internal header file, included by other library headers. 34 * Do not attempt to use it directly. @headername{iterator} 35 */ 36 37 // GCC Note: based on version 1.12.0 of the Boost library. 38 39 #ifndef _BOOST_CONCEPT_CHECK_H 40 #define _BOOST_CONCEPT_CHECK_H 1 41 42 #ifdef _GLIBCXX_SYSHDR 43 #pragma GCC system_header 44 #endif 45 46 #include <bits/c++config.h> 47 #include <bits/stl_iterator_base_types.h> // for traits and tags 48 49 namespace std _GLIBCXX_VISIBILITY(default) 50 { 51 _GLIBCXX_BEGIN_NAMESPACE_VERSION 52 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER 53 struct _Bit_iterator; 54 struct _Bit_const_iterator; 55 _GLIBCXX_END_NAMESPACE_CONTAINER 56 _GLIBCXX_END_NAMESPACE_VERSION 57 } 58 59 namespace __gnu_debug 60 { 61 template<typename _Iterator, typename _Sequence, typename _Category> 62 class _Safe_iterator; 63 } 64 65 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 66 { 67 _GLIBCXX_BEGIN_NAMESPACE_VERSION 68 69 #pragma GCC diagnostic push 70 #pragma GCC diagnostic ignored "-Wunused-local-typedefs" 71 72 #define _IsUnused __attribute__ ((__unused__)) 73 74 // When the C-C code is in use, we would like this function to do as little 75 // as possible at runtime, use as few resources as possible, and hopefully 76 // be elided out of existence... hmmm. 77 template <class _Concept> 78 _GLIBCXX14_CONSTEXPR inline void __function_requires() 79 { 80 void (_Concept::*__x)() _IsUnused = &_Concept::__constraints; 81 } 82 83 // No definition: if this is referenced, there's a problem with 84 // the instantiating type not being one of the required integer types. 85 // Unfortunately, this results in a link-time error, not a compile-time error. 86 void __error_type_must_be_an_integer_type(); 87 void __error_type_must_be_an_unsigned_integer_type(); 88 void __error_type_must_be_a_signed_integer_type(); 89 90 // ??? Should the "concept_checking*" structs begin with more than _ ? 91 #define _GLIBCXX_CLASS_REQUIRES(_type_var, _ns, _concept) \ 92 typedef void (_ns::_concept <_type_var>::* _func##_type_var##_concept)(); \ 93 template <_func##_type_var##_concept _Tp1> \ 94 struct _concept_checking##_type_var##_concept { }; \ 95 typedef _concept_checking##_type_var##_concept< \ 96 &_ns::_concept <_type_var>::__constraints> \ 97 _concept_checking_typedef##_type_var##_concept 98 99 #define _GLIBCXX_CLASS_REQUIRES2(_type_var1, _type_var2, _ns, _concept) \ 100 typedef void (_ns::_concept <_type_var1,_type_var2>::* _func##_type_var1##_type_var2##_concept)(); \ 101 template <_func##_type_var1##_type_var2##_concept _Tp1> \ 102 struct _concept_checking##_type_var1##_type_var2##_concept { }; \ 103 typedef _concept_checking##_type_var1##_type_var2##_concept< \ 104 &_ns::_concept <_type_var1,_type_var2>::__constraints> \ 105 _concept_checking_typedef##_type_var1##_type_var2##_concept 106 107 #define _GLIBCXX_CLASS_REQUIRES3(_type_var1, _type_var2, _type_var3, _ns, _concept) \ 108 typedef void (_ns::_concept <_type_var1,_type_var2,_type_var3>::* _func##_type_var1##_type_var2##_type_var3##_concept)(); \ 109 template <_func##_type_var1##_type_var2##_type_var3##_concept _Tp1> \ 110 struct _concept_checking##_type_var1##_type_var2##_type_var3##_concept { }; \ 111 typedef _concept_checking##_type_var1##_type_var2##_type_var3##_concept< \ 112 &_ns::_concept <_type_var1,_type_var2,_type_var3>::__constraints> \ 113 _concept_checking_typedef##_type_var1##_type_var2##_type_var3##_concept 114 115 #define _GLIBCXX_CLASS_REQUIRES4(_type_var1, _type_var2, _type_var3, _type_var4, _ns, _concept) \ 116 typedef void (_ns::_concept <_type_var1,_type_var2,_type_var3,_type_var4>::* _func##_type_var1##_type_var2##_type_var3##_type_var4##_concept)(); \ 117 template <_func##_type_var1##_type_var2##_type_var3##_type_var4##_concept _Tp1> \ 118 struct _concept_checking##_type_var1##_type_var2##_type_var3##_type_var4##_concept { }; \ 119 typedef _concept_checking##_type_var1##_type_var2##_type_var3##_type_var4##_concept< \ 120 &_ns::_concept <_type_var1,_type_var2,_type_var3,_type_var4>::__constraints> \ 121 _concept_checking_typedef##_type_var1##_type_var2##_type_var3##_type_var4##_concept 122 123 124 template <class _Tp1, class _Tp2> 125 struct _Aux_require_same { }; 126 127 template <class _Tp> 128 struct _Aux_require_same<_Tp,_Tp> { typedef _Tp _Type; }; 129 130 template <class _Tp1, class _Tp2> 131 struct _SameTypeConcept 132 { 133 void __constraints() { 134 typedef typename _Aux_require_same<_Tp1, _Tp2>::_Type _Required; 135 } 136 }; 137 138 template <class _Tp> 139 struct _IntegerConcept { 140 void __constraints() { 141 __error_type_must_be_an_integer_type(); 142 } 143 }; 144 template <> struct _IntegerConcept<short> { void __constraints() {} }; 145 template <> struct _IntegerConcept<unsigned short> { void __constraints(){} }; 146 template <> struct _IntegerConcept<int> { void __constraints() {} }; 147 template <> struct _IntegerConcept<unsigned int> { void __constraints() {} }; 148 template <> struct _IntegerConcept<long> { void __constraints() {} }; 149 template <> struct _IntegerConcept<unsigned long> { void __constraints() {} }; 150 template <> struct _IntegerConcept<long long> { void __constraints() {} }; 151 template <> struct _IntegerConcept<unsigned long long> 152 { void __constraints() {} }; 153 154 template <class _Tp> 155 struct _SignedIntegerConcept { 156 void __constraints() { 157 __error_type_must_be_a_signed_integer_type(); 158 } 159 }; 160 template <> struct _SignedIntegerConcept<short> { void __constraints() {} }; 161 template <> struct _SignedIntegerConcept<int> { void __constraints() {} }; 162 template <> struct _SignedIntegerConcept<long> { void __constraints() {} }; 163 template <> struct _SignedIntegerConcept<long long> { void __constraints(){}}; 164 165 template <class _Tp> 166 struct _UnsignedIntegerConcept { 167 void __constraints() { 168 __error_type_must_be_an_unsigned_integer_type(); 169 } 170 }; 171 template <> struct _UnsignedIntegerConcept<unsigned short> 172 { void __constraints() {} }; 173 template <> struct _UnsignedIntegerConcept<unsigned int> 174 { void __constraints() {} }; 175 template <> struct _UnsignedIntegerConcept<unsigned long> 176 { void __constraints() {} }; 177 template <> struct _UnsignedIntegerConcept<unsigned long long> 178 { void __constraints() {} }; 179 180 //=========================================================================== 181 // Basic Concepts 182 183 template <class _Tp> 184 struct _DefaultConstructibleConcept 185 { 186 void __constraints() { 187 _Tp __a _IsUnused; // require default constructor 188 } 189 }; 190 191 template <class _Tp> 192 struct _AssignableConcept 193 { 194 void __constraints() { 195 __a = __a; // require assignment operator 196 __const_constraints(__a); 197 } 198 void __const_constraints(const _Tp& __b) { 199 __a = __b; // const required for argument to assignment 200 } 201 _Tp __a; 202 // possibly should be "Tp* a;" and then dereference "a" in constraint 203 // functions? present way would require a default ctor, i think... 204 }; 205 206 template <class _Tp> 207 struct _CopyConstructibleConcept 208 { 209 void __constraints() { 210 _Tp __a(__b); // require copy constructor 211 _Tp* __ptr _IsUnused = &__a; // require address of operator 212 __const_constraints(__a); 213 } 214 void __const_constraints(const _Tp& __a) { 215 _Tp __c _IsUnused(__a); // require const copy constructor 216 const _Tp* __ptr _IsUnused = &__a; // require const address of operator 217 } 218 _Tp __b; 219 }; 220 221 // The SGI STL version of Assignable requires copy constructor and operator= 222 template <class _Tp> 223 struct _SGIAssignableConcept 224 { 225 void __constraints() { 226 _Tp __b _IsUnused(__a); 227 __a = __a; // require assignment operator 228 __const_constraints(__a); 229 } 230 void __const_constraints(const _Tp& __b) { 231 _Tp __c _IsUnused(__b); 232 __a = __b; // const required for argument to assignment 233 } 234 _Tp __a; 235 }; 236 237 template <class _From, class _To> 238 struct _ConvertibleConcept 239 { 240 void __constraints() { 241 _To __y _IsUnused = __x; 242 } 243 _From __x; 244 }; 245 246 // The C++ standard requirements for many concepts talk about return 247 // types that must be "convertible to bool". The problem with this 248 // requirement is that it leaves the door open for evil proxies that 249 // define things like operator|| with strange return types. Two 250 // possible solutions are: 251 // 1) require the return type to be exactly bool 252 // 2) stay with convertible to bool, and also 253 // specify stuff about all the logical operators. 254 // For now we just test for convertible to bool. 255 template <class _Tp> 256 void __aux_require_boolean_expr(const _Tp& __t) { 257 bool __x _IsUnused = __t; 258 } 259 260 // FIXME 261 template <class _Tp> 262 struct _EqualityComparableConcept 263 { 264 void __constraints() { 265 __aux_require_boolean_expr(__a == __b); 266 } 267 _Tp __a, __b; 268 }; 269 270 template <class _Tp> 271 struct _LessThanComparableConcept 272 { 273 void __constraints() { 274 __aux_require_boolean_expr(__a < __b); 275 } 276 _Tp __a, __b; 277 }; 278 279 // This is equivalent to SGI STL's LessThanComparable. 280 template <class _Tp> 281 struct _ComparableConcept 282 { 283 void __constraints() { 284 __aux_require_boolean_expr(__a < __b); 285 __aux_require_boolean_expr(__a > __b); 286 __aux_require_boolean_expr(__a <= __b); 287 __aux_require_boolean_expr(__a >= __b); 288 } 289 _Tp __a, __b; 290 }; 291 292 #define _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(_OP,_NAME) \ 293 template <class _First, class _Second> \ 294 struct _NAME { \ 295 void __constraints() { (void)__constraints_(); } \ 296 bool __constraints_() { \ 297 return __a _OP __b; \ 298 } \ 299 _First __a; \ 300 _Second __b; \ 301 } 302 303 #define _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(_OP,_NAME) \ 304 template <class _Ret, class _First, class _Second> \ 305 struct _NAME { \ 306 void __constraints() { (void)__constraints_(); } \ 307 _Ret __constraints_() { \ 308 return __a _OP __b; \ 309 } \ 310 _First __a; \ 311 _Second __b; \ 312 } 313 314 _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(==, _EqualOpConcept); 315 _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(!=, _NotEqualOpConcept); 316 _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<, _LessThanOpConcept); 317 _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<=, _LessEqualOpConcept); 318 _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>, _GreaterThanOpConcept); 319 _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>=, _GreaterEqualOpConcept); 320 321 _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(+, _PlusOpConcept); 322 _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(*, _TimesOpConcept); 323 _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(/, _DivideOpConcept); 324 _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(-, _SubtractOpConcept); 325 _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(%, _ModOpConcept); 326 327 #undef _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT 328 #undef _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT 329 330 //=========================================================================== 331 // Function Object Concepts 332 333 template <class _Func, class _Return> 334 struct _GeneratorConcept 335 { 336 void __constraints() { 337 const _Return& __r _IsUnused = __f();// require operator() member function 338 } 339 _Func __f; 340 }; 341 342 343 template <class _Func> 344 struct _GeneratorConcept<_Func,void> 345 { 346 void __constraints() { 347 __f(); // require operator() member function 348 } 349 _Func __f; 350 }; 351 352 template <class _Func, class _Return, class _Arg> 353 struct _UnaryFunctionConcept 354 { 355 void __constraints() { 356 __r = __f(__arg); // require operator() 357 } 358 _Func __f; 359 _Arg __arg; 360 _Return __r; 361 }; 362 363 template <class _Func, class _Arg> 364 struct _UnaryFunctionConcept<_Func, void, _Arg> { 365 void __constraints() { 366 __f(__arg); // require operator() 367 } 368 _Func __f; 369 _Arg __arg; 370 }; 371 372 template <class _Func, class _Return, class _First, class _Second> 373 struct _BinaryFunctionConcept 374 { 375 void __constraints() { 376 __r = __f(__first, __second); // require operator() 377 } 378 _Func __f; 379 _First __first; 380 _Second __second; 381 _Return __r; 382 }; 383 384 template <class _Func, class _First, class _Second> 385 struct _BinaryFunctionConcept<_Func, void, _First, _Second> 386 { 387 void __constraints() { 388 __f(__first, __second); // require operator() 389 } 390 _Func __f; 391 _First __first; 392 _Second __second; 393 }; 394 395 template <class _Func, class _Arg> 396 struct _UnaryPredicateConcept 397 { 398 void __constraints() { 399 __aux_require_boolean_expr(__f(__arg)); // require op() returning bool 400 } 401 _Func __f; 402 _Arg __arg; 403 }; 404 405 template <class _Func, class _First, class _Second> 406 struct _BinaryPredicateConcept 407 { 408 void __constraints() { 409 __aux_require_boolean_expr(__f(__a, __b)); // require op() returning bool 410 } 411 _Func __f; 412 _First __a; 413 _Second __b; 414 }; 415 416 // use this when functor is used inside a container class like std::set 417 template <class _Func, class _First, class _Second> 418 struct _Const_BinaryPredicateConcept { 419 void __constraints() { 420 __const_constraints(__f); 421 } 422 void __const_constraints(const _Func& __fun) { 423 __function_requires<_BinaryPredicateConcept<_Func, _First, _Second> >(); 424 // operator() must be a const member function 425 __aux_require_boolean_expr(__fun(__a, __b)); 426 } 427 _Func __f; 428 _First __a; 429 _Second __b; 430 }; 431 432 //=========================================================================== 433 // Iterator Concepts 434 435 template <class _Tp> 436 struct _TrivialIteratorConcept 437 { 438 void __constraints() { 439 // __function_requires< _DefaultConstructibleConcept<_Tp> >(); 440 __function_requires< _AssignableConcept<_Tp> >(); 441 __function_requires< _EqualityComparableConcept<_Tp> >(); 442 // typedef typename std::iterator_traits<_Tp>::value_type _V; 443 (void)*__i; // require dereference operator 444 } 445 _Tp __i; 446 }; 447 448 template <class _Tp> 449 struct _Mutable_TrivialIteratorConcept 450 { 451 void __constraints() { 452 __function_requires< _TrivialIteratorConcept<_Tp> >(); 453 *__i = *__j; // require dereference and assignment 454 } 455 _Tp __i, __j; 456 }; 457 458 template <class _Tp> 459 struct _InputIteratorConcept 460 { 461 void __constraints() { 462 __function_requires< _TrivialIteratorConcept<_Tp> >(); 463 // require iterator_traits typedef's 464 typedef typename std::iterator_traits<_Tp>::difference_type _Diff; 465 // __function_requires< _SignedIntegerConcept<_Diff> >(); 466 typedef typename std::iterator_traits<_Tp>::reference _Ref; 467 typedef typename std::iterator_traits<_Tp>::pointer _Pt; 468 typedef typename std::iterator_traits<_Tp>::iterator_category _Cat; 469 __function_requires< _ConvertibleConcept< 470 typename std::iterator_traits<_Tp>::iterator_category, 471 std::input_iterator_tag> >(); 472 ++__i; // require preincrement operator 473 __i++; // require postincrement operator 474 } 475 _Tp __i; 476 }; 477 478 template <class _Tp, class _ValueT> 479 struct _OutputIteratorConcept 480 { 481 void __constraints() { 482 __function_requires< _AssignableConcept<_Tp> >(); 483 ++__i; // require preincrement operator 484 __i++; // require postincrement operator 485 *__i++ = __val(); // require postincrement and assignment 486 } 487 _Tp __i; 488 // Use a function pointer here so no definition of the function needed. 489 // Just need something that returns a _ValueT (which might be a reference). 490 _ValueT (*__val)(); 491 }; 492 493 template<typename _Tp> 494 struct _Is_vector_bool_iterator 495 { static const bool __value = false; }; 496 497 #ifdef _GLIBCXX_DEBUG 498 namespace __cont = ::std::_GLIBCXX_STD_C; 499 #else 500 namespace __cont = ::std; 501 #endif 502 503 // Trait to identify vector<bool>::iterator 504 template <> 505 struct _Is_vector_bool_iterator<__cont::_Bit_iterator> 506 { static const bool __value = true; }; 507 508 // And for vector<bool>::const_iterator. 509 template <> 510 struct _Is_vector_bool_iterator<__cont::_Bit_const_iterator> 511 { static const bool __value = true; }; 512 513 // And for __gnu_debug::vector<bool> iterators too. 514 template <typename _It, typename _Seq, typename _Tag> 515 struct _Is_vector_bool_iterator<__gnu_debug::_Safe_iterator<_It, _Seq, _Tag> > 516 : _Is_vector_bool_iterator<_It> { }; 517 518 template <class _Tp, bool = _Is_vector_bool_iterator<_Tp>::__value> 519 struct _ForwardIteratorReferenceConcept 520 { 521 void __constraints() { 522 #if __cplusplus >= 201103L 523 typedef typename std::iterator_traits<_Tp>::reference _Ref; 524 static_assert(std::is_reference<_Ref>::value, 525 "reference type of a forward iterator must be a real reference"); 526 #endif 527 } 528 }; 529 530 template <class _Tp, bool = _Is_vector_bool_iterator<_Tp>::__value> 531 struct _Mutable_ForwardIteratorReferenceConcept 532 { 533 void __constraints() { 534 typedef typename std::iterator_traits<_Tp>::reference _Ref; 535 typedef typename std::iterator_traits<_Tp>::value_type _Val; 536 __function_requires< _SameTypeConcept<_Ref, _Val&> >(); 537 } 538 }; 539 540 // vector<bool> iterators are not real forward iterators, but we ignore that. 541 template <class _Tp> 542 struct _ForwardIteratorReferenceConcept<_Tp, true> 543 { 544 void __constraints() { } 545 }; 546 547 // vector<bool> iterators are not real forward iterators, but we ignore that. 548 template <class _Tp> 549 struct _Mutable_ForwardIteratorReferenceConcept<_Tp, true> 550 { 551 void __constraints() { } 552 }; 553 554 #pragma GCC diagnostic push 555 #pragma GCC diagnostic ignored "-Wunused-variable" 556 557 template <class _Tp> 558 struct _ForwardIteratorConcept 559 { 560 void __constraints() { 561 __function_requires< _InputIteratorConcept<_Tp> >(); 562 __function_requires< _DefaultConstructibleConcept<_Tp> >(); 563 __function_requires< _ConvertibleConcept< 564 typename std::iterator_traits<_Tp>::iterator_category, 565 std::forward_iterator_tag> >(); 566 __function_requires< _ForwardIteratorReferenceConcept<_Tp> >(); 567 _Tp& __j = ++__i; 568 const _Tp& __k = __i++; 569 typedef typename std::iterator_traits<_Tp>::reference _Ref; 570 _Ref __r = *__k; 571 _Ref __r2 = *__i++; 572 } 573 _Tp __i; 574 }; 575 576 template <class _Tp> 577 struct _Mutable_ForwardIteratorConcept 578 { 579 void __constraints() { 580 __function_requires< _ForwardIteratorConcept<_Tp> >(); 581 typedef typename std::iterator_traits<_Tp>::reference _Ref; 582 typedef typename std::iterator_traits<_Tp>::value_type _Val; 583 __function_requires< _Mutable_ForwardIteratorReferenceConcept<_Tp> >(); 584 } 585 _Tp __i; 586 }; 587 588 template <class _Tp> 589 struct _BidirectionalIteratorConcept 590 { 591 void __constraints() { 592 __function_requires< _ForwardIteratorConcept<_Tp> >(); 593 __function_requires< _ConvertibleConcept< 594 typename std::iterator_traits<_Tp>::iterator_category, 595 std::bidirectional_iterator_tag> >(); 596 _Tp& __j = --__i; // require predecrement operator 597 const _Tp& __k = __i--; // require postdecrement operator 598 typedef typename std::iterator_traits<_Tp>::reference _Ref; 599 _Ref __r = *__j--; 600 } 601 _Tp __i; 602 }; 603 604 template <class _Tp> 605 struct _Mutable_BidirectionalIteratorConcept 606 { 607 void __constraints() { 608 __function_requires< _BidirectionalIteratorConcept<_Tp> >(); 609 __function_requires< _Mutable_ForwardIteratorConcept<_Tp> >(); 610 } 611 _Tp __i; 612 }; 613 614 615 template <class _Tp> 616 struct _RandomAccessIteratorConcept 617 { 618 void __constraints() { 619 __function_requires< _BidirectionalIteratorConcept<_Tp> >(); 620 __function_requires< _ComparableConcept<_Tp> >(); 621 __function_requires< _ConvertibleConcept< 622 typename std::iterator_traits<_Tp>::iterator_category, 623 std::random_access_iterator_tag> >(); 624 typedef typename std::iterator_traits<_Tp>::reference _Ref; 625 626 _Tp& __j = __i += __n; // require assignment addition operator 627 __i = __i + __n; __i = __n + __i; // require addition with difference type 628 _Tp& __k = __i -= __n; // require assignment subtraction op 629 __i = __i - __n; // require subtraction with 630 // difference type 631 __n = __i - __j; // require difference operator 632 _Ref __r = __i[__n]; // require element access operator 633 } 634 _Tp __a, __b; 635 _Tp __i, __j; 636 typename std::iterator_traits<_Tp>::difference_type __n; 637 }; 638 639 template <class _Tp> 640 struct _Mutable_RandomAccessIteratorConcept 641 { 642 void __constraints() { 643 __function_requires< _RandomAccessIteratorConcept<_Tp> >(); 644 __function_requires< _Mutable_BidirectionalIteratorConcept<_Tp> >(); 645 } 646 _Tp __i; 647 typename std::iterator_traits<_Tp>::difference_type __n; 648 }; 649 650 #pragma GCC diagnostic pop 651 652 //=========================================================================== 653 // Container Concepts 654 655 template <class _Container> 656 struct _ContainerConcept 657 { 658 typedef typename _Container::value_type _Value_type; 659 typedef typename _Container::difference_type _Difference_type; 660 typedef typename _Container::size_type _Size_type; 661 typedef typename _Container::const_reference _Const_reference; 662 typedef typename _Container::const_pointer _Const_pointer; 663 typedef typename _Container::const_iterator _Const_iterator; 664 665 void __constraints() { 666 __function_requires< _InputIteratorConcept<_Const_iterator> >(); 667 __function_requires< _AssignableConcept<_Container> >(); 668 const _Container __c; 669 __i = __c.begin(); 670 __i = __c.end(); 671 __n = __c.size(); 672 __n = __c.max_size(); 673 __b = __c.empty(); 674 } 675 bool __b; 676 _Const_iterator __i; 677 _Size_type __n; 678 }; 679 680 template <class _Container> 681 struct _Mutable_ContainerConcept 682 { 683 typedef typename _Container::value_type _Value_type; 684 typedef typename _Container::reference _Reference; 685 typedef typename _Container::iterator _Iterator; 686 typedef typename _Container::pointer _Pointer; 687 688 void __constraints() { 689 __function_requires< _ContainerConcept<_Container> >(); 690 __function_requires< _AssignableConcept<_Value_type> >(); 691 __function_requires< _InputIteratorConcept<_Iterator> >(); 692 693 __i = __c.begin(); 694 __i = __c.end(); 695 __c.swap(__c2); 696 } 697 _Iterator __i; 698 _Container __c, __c2; 699 }; 700 701 template <class _ForwardContainer> 702 struct _ForwardContainerConcept 703 { 704 void __constraints() { 705 __function_requires< _ContainerConcept<_ForwardContainer> >(); 706 typedef typename _ForwardContainer::const_iterator _Const_iterator; 707 __function_requires< _ForwardIteratorConcept<_Const_iterator> >(); 708 } 709 }; 710 711 template <class _ForwardContainer> 712 struct _Mutable_ForwardContainerConcept 713 { 714 void __constraints() { 715 __function_requires< _ForwardContainerConcept<_ForwardContainer> >(); 716 __function_requires< _Mutable_ContainerConcept<_ForwardContainer> >(); 717 typedef typename _ForwardContainer::iterator _Iterator; 718 __function_requires< _Mutable_ForwardIteratorConcept<_Iterator> >(); 719 } 720 }; 721 722 template <class _ReversibleContainer> 723 struct _ReversibleContainerConcept 724 { 725 typedef typename _ReversibleContainer::const_iterator _Const_iterator; 726 typedef typename _ReversibleContainer::const_reverse_iterator 727 _Const_reverse_iterator; 728 729 void __constraints() { 730 __function_requires< _ForwardContainerConcept<_ReversibleContainer> >(); 731 __function_requires< _BidirectionalIteratorConcept<_Const_iterator> >(); 732 __function_requires< 733 _BidirectionalIteratorConcept<_Const_reverse_iterator> >(); 734 735 const _ReversibleContainer __c; 736 _Const_reverse_iterator __i = __c.rbegin(); 737 __i = __c.rend(); 738 } 739 }; 740 741 template <class _ReversibleContainer> 742 struct _Mutable_ReversibleContainerConcept 743 { 744 typedef typename _ReversibleContainer::iterator _Iterator; 745 typedef typename _ReversibleContainer::reverse_iterator _Reverse_iterator; 746 747 void __constraints() { 748 __function_requires<_ReversibleContainerConcept<_ReversibleContainer> >(); 749 __function_requires< 750 _Mutable_ForwardContainerConcept<_ReversibleContainer> >(); 751 __function_requires<_Mutable_BidirectionalIteratorConcept<_Iterator> >(); 752 __function_requires< 753 _Mutable_BidirectionalIteratorConcept<_Reverse_iterator> >(); 754 755 _Reverse_iterator __i = __c.rbegin(); 756 __i = __c.rend(); 757 } 758 _ReversibleContainer __c; 759 }; 760 761 template <class _RandomAccessContainer> 762 struct _RandomAccessContainerConcept 763 { 764 typedef typename _RandomAccessContainer::size_type _Size_type; 765 typedef typename _RandomAccessContainer::const_reference _Const_reference; 766 typedef typename _RandomAccessContainer::const_iterator _Const_iterator; 767 typedef typename _RandomAccessContainer::const_reverse_iterator 768 _Const_reverse_iterator; 769 770 void __constraints() { 771 __function_requires< 772 _ReversibleContainerConcept<_RandomAccessContainer> >(); 773 __function_requires< _RandomAccessIteratorConcept<_Const_iterator> >(); 774 __function_requires< 775 _RandomAccessIteratorConcept<_Const_reverse_iterator> >(); 776 777 const _RandomAccessContainer __c; 778 _Const_reference __r _IsUnused = __c[__n]; 779 } 780 _Size_type __n; 781 }; 782 783 template <class _RandomAccessContainer> 784 struct _Mutable_RandomAccessContainerConcept 785 { 786 typedef typename _RandomAccessContainer::size_type _Size_type; 787 typedef typename _RandomAccessContainer::reference _Reference; 788 typedef typename _RandomAccessContainer::iterator _Iterator; 789 typedef typename _RandomAccessContainer::reverse_iterator _Reverse_iterator; 790 791 void __constraints() { 792 __function_requires< 793 _RandomAccessContainerConcept<_RandomAccessContainer> >(); 794 __function_requires< 795 _Mutable_ReversibleContainerConcept<_RandomAccessContainer> >(); 796 __function_requires< _Mutable_RandomAccessIteratorConcept<_Iterator> >(); 797 __function_requires< 798 _Mutable_RandomAccessIteratorConcept<_Reverse_iterator> >(); 799 800 _Reference __r _IsUnused = __c[__i]; 801 } 802 _Size_type __i; 803 _RandomAccessContainer __c; 804 }; 805 806 // A Sequence is inherently mutable 807 template <class _Sequence> 808 struct _SequenceConcept 809 { 810 typedef typename _Sequence::reference _Reference; 811 typedef typename _Sequence::const_reference _Const_reference; 812 813 void __constraints() { 814 // Matt Austern's book puts DefaultConstructible here, the C++ 815 // standard places it in Container 816 // function_requires< DefaultConstructible<Sequence> >(); 817 __function_requires< _Mutable_ForwardContainerConcept<_Sequence> >(); 818 __function_requires< _DefaultConstructibleConcept<_Sequence> >(); 819 820 _Sequence 821 __c _IsUnused(__n, __t), 822 __c2 _IsUnused(__first, __last); 823 824 __c.insert(__p, __t); 825 __c.insert(__p, __n, __t); 826 __c.insert(__p, __first, __last); 827 828 __c.erase(__p); 829 __c.erase(__p, __q); 830 831 _Reference __r _IsUnused = __c.front(); 832 833 __const_constraints(__c); 834 } 835 void __const_constraints(const _Sequence& __c) { 836 _Const_reference __r _IsUnused = __c.front(); 837 } 838 typename _Sequence::value_type __t; 839 typename _Sequence::size_type __n; 840 typename _Sequence::value_type *__first, *__last; 841 typename _Sequence::iterator __p, __q; 842 }; 843 844 template <class _FrontInsertionSequence> 845 struct _FrontInsertionSequenceConcept 846 { 847 void __constraints() { 848 __function_requires< _SequenceConcept<_FrontInsertionSequence> >(); 849 850 __c.push_front(__t); 851 __c.pop_front(); 852 } 853 _FrontInsertionSequence __c; 854 typename _FrontInsertionSequence::value_type __t; 855 }; 856 857 template <class _BackInsertionSequence> 858 struct _BackInsertionSequenceConcept 859 { 860 typedef typename _BackInsertionSequence::reference _Reference; 861 typedef typename _BackInsertionSequence::const_reference _Const_reference; 862 863 void __constraints() { 864 __function_requires< _SequenceConcept<_BackInsertionSequence> >(); 865 866 __c.push_back(__t); 867 __c.pop_back(); 868 _Reference __r _IsUnused = __c.back(); 869 } 870 void __const_constraints(const _BackInsertionSequence& __c) { 871 _Const_reference __r _IsUnused = __c.back(); 872 }; 873 _BackInsertionSequence __c; 874 typename _BackInsertionSequence::value_type __t; 875 }; 876 877 _GLIBCXX_END_NAMESPACE_VERSION 878 } // namespace 879 880 #pragma GCC diagnostic pop 881 #undef _IsUnused 882 883 #endif // _GLIBCXX_BOOST_CONCEPT_CHECK 884 885