1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
|
#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_CUSTOM_ITERATOR_H
#define TEST_INTEROP_CXX_STDLIB_INPUTS_CUSTOM_ITERATOR_H
#include <cstddef>
#include <iterator>
// MARK: Valid iterator types
struct ConstIterator {
private:
int value;
public:
using iterator_category = std::input_iterator_tag;
using value_type = int;
using pointer = int *;
using reference = const int &;
using difference_type = int;
ConstIterator(int value) : value(value) {}
ConstIterator(const ConstIterator &other) = default;
const int &operator*() const { return value; }
ConstIterator &operator++() {
value++;
return *this;
}
ConstIterator operator++(int) {
auto tmp = ConstIterator(value);
value++;
return tmp;
}
bool operator==(const ConstIterator &other) const {
return value == other.value;
}
bool operator!=(const ConstIterator &other) const {
return value != other.value;
}
};
struct ConstRACIterator {
private:
int value;
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = int;
using pointer = int *;
using reference = const int &;
using difference_type = int;
ConstRACIterator(int value) : value(value) {}
ConstRACIterator(const ConstRACIterator &other) = default;
const int &operator*() const { return value; }
ConstRACIterator &operator++() {
value++;
return *this;
}
ConstRACIterator operator++(int) {
auto tmp = ConstRACIterator(value);
value++;
return tmp;
}
void operator+=(difference_type v) { value += v; }
void operator-=(difference_type v) { value -= v; }
ConstRACIterator operator+(difference_type v) const {
return ConstRACIterator(value + v);
}
ConstRACIterator operator-(difference_type v) const {
return ConstRACIterator(value - v);
}
friend ConstRACIterator operator+(difference_type v,
const ConstRACIterator &it) {
return it + v;
}
int operator-(const ConstRACIterator &other) const {
return value - other.value;
}
bool operator<(const ConstRACIterator &other) const {
return value < other.value;
}
bool operator==(const ConstRACIterator &other) const {
return value == other.value;
}
bool operator!=(const ConstRACIterator &other) const {
return value != other.value;
}
};
// Same as ConstRACIterator, but operator+= returns a reference to this.
struct ConstRACIteratorRefPlusEq {
private:
int value;
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = int;
using pointer = int *;
using reference = const int &;
using difference_type = int;
ConstRACIteratorRefPlusEq(int value) : value(value) {}
ConstRACIteratorRefPlusEq(const ConstRACIteratorRefPlusEq &other) = default;
const int &operator*() const { return value; }
ConstRACIteratorRefPlusEq &operator++() {
value++;
return *this;
}
ConstRACIteratorRefPlusEq operator++(int) {
auto tmp = ConstRACIteratorRefPlusEq(value);
value++;
return tmp;
}
ConstRACIteratorRefPlusEq &operator+=(difference_type v) {
value += v;
return *this;
}
ConstRACIteratorRefPlusEq &operator-=(difference_type v) {
value -= v;
return *this;
}
ConstRACIteratorRefPlusEq operator+(difference_type v) const {
return ConstRACIteratorRefPlusEq(value + v);
}
ConstRACIteratorRefPlusEq operator-(difference_type v) const {
return ConstRACIteratorRefPlusEq(value - v);
}
friend ConstRACIteratorRefPlusEq
operator+(difference_type v, const ConstRACIteratorRefPlusEq &it) {
return it + v;
}
int operator-(const ConstRACIteratorRefPlusEq &other) const {
return value - other.value;
}
bool operator<(const ConstRACIteratorRefPlusEq &other) const {
return value < other.value;
}
bool operator==(const ConstRACIteratorRefPlusEq &other) const {
return value == other.value;
}
bool operator!=(const ConstRACIteratorRefPlusEq &other) const {
return value != other.value;
}
};
/// Same as ConstIterator, but defines `operator==` as a non-member.
struct ConstIteratorOutOfLineEq {
int value;
using iterator_category = std::input_iterator_tag;
using value_type = int;
using pointer = int *;
using reference = int &;
using difference_type = int;
ConstIteratorOutOfLineEq(int value) : value(value) {}
ConstIteratorOutOfLineEq(const ConstIteratorOutOfLineEq &other) = default;
const int &operator*() const { return value; }
ConstIteratorOutOfLineEq &operator++() {
value++;
return *this;
}
ConstIteratorOutOfLineEq operator++(int) {
auto tmp = ConstIteratorOutOfLineEq(value);
value++;
return tmp;
}
};
bool operator==(const ConstIteratorOutOfLineEq &lhs,
const ConstIteratorOutOfLineEq &rhs) {
return lhs.value == rhs.value;
}
bool operator!=(const ConstIteratorOutOfLineEq &lhs,
const ConstIteratorOutOfLineEq &rhs) {
return lhs.value != rhs.value;
}
/// Only satisfies the minimal requirements for an iterator.
struct MinimalIterator {
int value;
using iterator_category = std::input_iterator_tag;
const int &operator*() const { return value; }
MinimalIterator &operator++() {
value++;
return *this;
}
bool operator==(const MinimalIterator &other) const {
return value == other.value;
}
};
struct ForwardIterator {
int value;
using iterator_category = std::forward_iterator_tag;
using reference = const int &;
const int &operator*() const { return value; }
ForwardIterator &operator++() {
value++;
return *this;
}
ForwardIterator operator++(int) {
ForwardIterator tmp = {value};
value++;
return tmp;
}
bool operator==(const ForwardIterator &other) const {
return value == other.value;
}
};
struct HasCustomIteratorTag {
struct CustomTag : public std::input_iterator_tag {};
int value;
using iterator_category = CustomTag;
const int &operator*() const { return value; }
HasCustomIteratorTag &operator++() {
value++;
return *this;
}
bool operator==(const HasCustomIteratorTag &other) const {
return value == other.value;
}
};
struct HasCustomRACIteratorTag {
struct CustomTag : public std::random_access_iterator_tag {};
int value;
using iterator_category = CustomTag;
const int &operator*() const { return value; }
HasCustomRACIteratorTag &operator++() {
value++;
return *this;
}
void operator+=(int x) { value += x; }
int operator-(const HasCustomRACIteratorTag &x) const {
return value - x.value;
}
bool operator==(const HasCustomRACIteratorTag &other) const {
return value == other.value;
}
};
struct HasCustomIteratorTagInline {
struct iterator_category : public std::input_iterator_tag {};
int value;
const int &operator*() const { return value; }
HasCustomIteratorTagInline &operator++() {
value++;
return *this;
}
bool operator==(const HasCustomIteratorTagInline &other) const {
return value == other.value;
}
};
struct HasTypedefIteratorTag {
int value;
typedef std::input_iterator_tag iterator_category;
const int &operator*() const { return value; }
HasTypedefIteratorTag &operator++() {
value++;
return *this;
}
bool operator==(const HasTypedefIteratorTag &other) const {
return value == other.value;
}
};
// MARK: Types that are not actually iterators
struct HasNoIteratorCategory {
int value;
const int &operator*() const { return value; }
HasNoIteratorCategory &operator++() {
value++;
return *this;
}
bool operator==(const HasNoIteratorCategory &other) const {
return value == other.value;
}
};
struct HasInvalidIteratorCategory {
struct NotAnIteratorTag {};
int value;
using iterator_category = NotAnIteratorTag;
const int &operator*() const { return value; }
HasInvalidIteratorCategory &operator++() {
value++;
return *this;
}
bool operator==(const HasInvalidIteratorCategory &other) const {
return value == other.value;
}
};
struct HasNoEqualEqual {
int value;
using iterator_category = std::input_iterator_tag;
const int &operator*() const { return value; }
HasNoEqualEqual &operator++() {
value++;
return *this;
}
};
struct HasInvalidEqualEqual {
int value;
using iterator_category = std::input_iterator_tag;
const int &operator*() const { return value; }
HasInvalidEqualEqual &operator++() {
value++;
return *this;
}
bool operator==(const int &other) const { // wrong type
return value == other;
}
};
struct HasNoIncrementOperator {
int value;
using iterator_category = std::input_iterator_tag;
const int &operator*() const { return value; }
bool operator==(const HasNoIncrementOperator &other) const {
return value == other.value;
}
};
struct HasNoPreIncrementOperator {
int value;
using iterator_category = std::input_iterator_tag;
const int &operator*() const { return value; }
HasNoPreIncrementOperator operator++(int) { // post-increment
HasNoPreIncrementOperator tmp = {value};
value++;
return tmp;
}
bool operator==(const HasNoPreIncrementOperator &other) const {
return value == other.value;
}
};
struct HasNoDereferenceOperator {
int value;
using iterator_category = std::input_iterator_tag;
HasNoDereferenceOperator &operator++() {
value++;
return *this;
}
bool operator==(const HasNoDereferenceOperator &other) const {
return value == other.value;
}
};
// MARK: Types that claim to be random access iterators, but actually aren't.
struct HasNoMinusOperator {
int value;
using iterator_category = std::random_access_iterator_tag;
using value_type = int;
using pointer = int *;
using reference = const int &;
using difference_type = int;
HasNoMinusOperator(int value) : value(value) {}
HasNoMinusOperator(const HasNoMinusOperator &other) = default;
const int &operator*() const { return value; }
HasNoMinusOperator &operator++() {
value++;
return *this;
}
void operator+=(difference_type v) { value += v; }
void operator-=(difference_type v) { value -= v; }
HasNoMinusOperator operator+(difference_type v) const {
return HasNoMinusOperator(value + v);
}
HasNoMinusOperator operator-(difference_type v) const {
return HasNoMinusOperator(value - v);
}
friend HasNoMinusOperator operator+(difference_type v,
const HasNoMinusOperator &it) {
return it + v;
}
bool operator<(const HasNoMinusOperator &other) const {
return value < other.value;
}
bool operator==(const HasNoMinusOperator &other) const {
return value == other.value;
}
bool operator!=(const HasNoMinusOperator &other) const {
return value != other.value;
}
};
struct HasNoPlusEqualOperator {
int value;
using iterator_category = std::random_access_iterator_tag;
using value_type = int;
using pointer = int *;
using reference = const int &;
using difference_type = int;
HasNoPlusEqualOperator(int value) : value(value) {}
HasNoPlusEqualOperator(const HasNoPlusEqualOperator &other) = default;
const int &operator*() const { return value; }
HasNoPlusEqualOperator &operator++() {
value++;
return *this;
}
void operator-=(difference_type v) { value -= v; }
HasNoPlusEqualOperator operator+(difference_type v) const {
return HasNoPlusEqualOperator(value + v);
}
HasNoPlusEqualOperator operator-(difference_type v) const {
return HasNoPlusEqualOperator(value - v);
}
friend HasNoPlusEqualOperator operator+(difference_type v,
const HasNoPlusEqualOperator &it) {
return it + v;
}
int operator-(const HasNoPlusEqualOperator &other) const {
return value - other.value;
}
bool operator<(const HasNoPlusEqualOperator &other) const {
return value < other.value;
}
bool operator==(const HasNoPlusEqualOperator &other) const {
return value == other.value;
}
bool operator!=(const HasNoPlusEqualOperator &other) const {
return value != other.value;
}
};
// MARK: Templated iterators
template <typename T>
struct TemplatedIterator {
T value;
using iterator_category = std::input_iterator_tag;
using value_type = T;
using pointer = T *;
using reference = const T &;
using difference_type = int;
TemplatedIterator(int value) : value(value) {}
TemplatedIterator(const TemplatedIterator &other) = default;
const int &operator*() const { return value; }
TemplatedIterator &operator++() {
value++;
return *this;
}
TemplatedIterator operator++(int) {
auto tmp = TemplatedIterator(value);
value++;
return tmp;
}
bool operator==(const TemplatedIterator &other) const {
return value == other.value;
}
};
using TemplatedIteratorInt = TemplatedIterator<int>;
template <typename T>
struct TemplatedIteratorOutOfLineEq {
T value;
using iterator_category = std::input_iterator_tag;
using value_type = T;
using pointer = T *;
using reference = const T &;
using difference_type = int;
TemplatedIteratorOutOfLineEq(int value) : value(value) {}
TemplatedIteratorOutOfLineEq(const TemplatedIteratorOutOfLineEq &other) =
default;
const int &operator*() const { return value; }
TemplatedIteratorOutOfLineEq &operator++() {
value++;
return *this;
}
TemplatedIteratorOutOfLineEq operator++(int) {
auto tmp = TemplatedIteratorOutOfLineEq(value);
value++;
return tmp;
}
};
template <typename T>
bool operator==(const TemplatedIteratorOutOfLineEq<T> &lhs,
const TemplatedIteratorOutOfLineEq<T> &rhs) {
return lhs.value == rhs.value;
}
using TemplatedIteratorOutOfLineEqInt = TemplatedIteratorOutOfLineEq<int>;
template <typename T>
struct TemplatedRACIteratorOutOfLineEq {
T value;
using iterator_category = std::random_access_iterator_tag;
using value_type = T;
using pointer = T *;
using reference = const T &;
using difference_type = int;
TemplatedRACIteratorOutOfLineEq(int value) : value(value) {}
TemplatedRACIteratorOutOfLineEq(const TemplatedRACIteratorOutOfLineEq &other) =
default;
const int &operator*() const { return value; }
TemplatedRACIteratorOutOfLineEq &operator++() {
value++;
return *this;
}
TemplatedRACIteratorOutOfLineEq &operator--() {
value--;
return *this;
}
TemplatedRACIteratorOutOfLineEq operator++(int) {
auto tmp = TemplatedRACIteratorOutOfLineEq(value);
value++;
return tmp;
}
TemplatedRACIteratorOutOfLineEq &operator+=(difference_type v) {
value += v;
return *this;
}
TemplatedRACIteratorOutOfLineEq &operator-=(difference_type v) {
value -= v;
return *this;
}
TemplatedRACIteratorOutOfLineEq operator+(difference_type v) const {
return TemplatedRACIteratorOutOfLineEq(value + v);
}
TemplatedRACIteratorOutOfLineEq operator-(difference_type v) const {
return TemplatedRACIteratorOutOfLineEq(value - v);
}
};
template <typename T>
bool operator==(const TemplatedRACIteratorOutOfLineEq<T> &lhs,
const TemplatedRACIteratorOutOfLineEq<T> &rhs) {
return lhs.value == rhs.value;
}
template <typename T>
typename TemplatedRACIteratorOutOfLineEq<T>::difference_type
operator-(const TemplatedRACIteratorOutOfLineEq<T> &lhs,
const TemplatedRACIteratorOutOfLineEq<T> &rhs) {
return lhs.value - rhs.value;
}
using TemplatedRACIteratorOutOfLineEqInt = TemplatedRACIteratorOutOfLineEq<int>;
// MARK: Iterator types that use inheritance
struct BaseIntIterator {
using value_type = int;
using reference = const int &;
int value;
BaseIntIterator(int value) : value(value) {}
reference operator*() const { return value; }
bool operator==(const BaseIntIterator &other) const {
return value == other.value;
}
bool operator!=(const BaseIntIterator &other) const {
return value != other.value;
}
};
struct InheritedConstIterator : BaseIntIterator {
using iterator_category = std::input_iterator_tag;
using pointer = int *;
using difference_type = int;
InheritedConstIterator(int value) : BaseIntIterator(value) {}
InheritedConstIterator(const InheritedConstIterator &other) = default;
InheritedConstIterator &operator++() {
value++;
return *this;
}
InheritedConstIterator operator++(int) {
auto tmp = InheritedConstIterator(value);
value++;
return tmp;
}
};
// MARK: Templated iterator types that use inheritance
template <typename T>
struct BaseTemplatedIterator {
using value_type = T;
using reference = const T &;
T value;
BaseTemplatedIterator(T value) : value(value) {}
reference operator*() const { return value; }
bool operator==(const BaseTemplatedIterator<T> &other) const {
return value == other.value;
}
bool operator!=(const BaseTemplatedIterator<T> &other) const {
return value != other.value;
}
};
template <typename T>
struct InheritedTemplatedConstIterator : BaseTemplatedIterator<T> {
using iterator_category = std::input_iterator_tag;
using pointer = int *;
using difference_type = int;
InheritedTemplatedConstIterator(T value) : BaseTemplatedIterator<T>(value) {}
InheritedTemplatedConstIterator(const InheritedTemplatedConstIterator<T> &other) = default;
InheritedTemplatedConstIterator<T> &operator++() {
BaseTemplatedIterator<T>::value++;
return *this;
}
InheritedTemplatedConstIterator<T> operator++(int) {
auto tmp = InheritedTemplatedConstIterator<T>(BaseTemplatedIterator<T>::value);
BaseTemplatedIterator<T>::value++;
return tmp;
}
};
typedef InheritedTemplatedConstIterator<int> InheritedTemplatedConstIteratorInt;
template <typename T>
struct BaseTemplatedRACIterator {
using value_type = T;
using reference = const T &;
using difference_type = int;
T value;
BaseTemplatedRACIterator(T value) : value(value) {}
reference operator*() const { return value; }
bool operator==(const BaseTemplatedRACIterator<T> &other) const {
return value == other.value;
}
bool operator!=(const BaseTemplatedRACIterator<T> &other) const {
return value != other.value;
}
};
template <typename T>
struct InheritedTemplatedConstRACIterator : BaseTemplatedRACIterator<T> {
using _super = BaseTemplatedRACIterator<T>;
using iterator_category = std::random_access_iterator_tag;
using pointer = int *;
InheritedTemplatedConstRACIterator(T value)
: BaseTemplatedRACIterator<T>(value) {}
InheritedTemplatedConstRACIterator(
const InheritedTemplatedConstRACIterator<T> &other) = default;
InheritedTemplatedConstRACIterator<T> &operator++() {
_super::value++;
return *this;
}
InheritedTemplatedConstRACIterator<T> operator++(int) {
auto tmp = InheritedTemplatedConstRACIterator<T>(_super::value);
_super::value++;
return tmp;
}
InheritedTemplatedConstRACIterator<T>
operator+(typename _super::difference_type v) const {
return {_super::value + v};
}
InheritedTemplatedConstRACIterator<T>
operator-(typename _super::difference_type v) const {
return {_super::value - v};
}
friend InheritedTemplatedConstRACIterator<T>
operator+(typename _super::difference_type v,
const InheritedTemplatedConstRACIterator<T> &it) {
return it + v;
}
int operator-(const InheritedTemplatedConstRACIterator<T> &other) const {
return _super::value - other.value;
}
void operator+=(typename _super::difference_type v) { _super::value += v; }
void operator-=(typename _super::difference_type v) { _super::value -= v; }
bool operator<(const InheritedTemplatedConstRACIterator<T> &other) const {
return _super::value < other.value;
}
};
typedef InheritedTemplatedConstRACIterator<int> InheritedTemplatedConstRACIteratorInt;
template <typename T>
struct BaseTemplatedRACIteratorOutOfLineOps {
using value_type = T;
using reference = const T &;
using difference_type = int;
T value;
BaseTemplatedRACIteratorOutOfLineOps(T value) : value(value) {}
reference operator*() const { return value; }
};
template <typename T>
bool operator==(const BaseTemplatedRACIteratorOutOfLineOps<T> &lhs,
const BaseTemplatedRACIteratorOutOfLineOps<T> &rhs) {
return lhs.value == rhs.value;
}
template <typename T>
bool operator!=(const BaseTemplatedRACIteratorOutOfLineOps<T> &lhs,
const BaseTemplatedRACIteratorOutOfLineOps<T> &rhs) {
return lhs.value != rhs.value;
}
template <typename T>
bool operator<(const BaseTemplatedRACIteratorOutOfLineOps<T> &lhs,
const BaseTemplatedRACIteratorOutOfLineOps<T> &rhs) {
return lhs.value < rhs.value;
}
template <typename T>
typename BaseTemplatedRACIteratorOutOfLineOps<T>::difference_type
operator-(const BaseTemplatedRACIteratorOutOfLineOps<T> &lhs,
const BaseTemplatedRACIteratorOutOfLineOps<T> &rhs) {
return lhs.value - rhs.value;
}
template <typename T>
BaseTemplatedRACIteratorOutOfLineOps<T> operator+(
const BaseTemplatedRACIteratorOutOfLineOps<T> &lhs,
typename BaseTemplatedRACIteratorOutOfLineOps<T>::difference_type rhs) {
return {lhs.value + rhs};
}
template <typename T>
BaseTemplatedRACIteratorOutOfLineOps<T> operator-(
const BaseTemplatedRACIteratorOutOfLineOps<T> &lhs,
typename BaseTemplatedRACIteratorOutOfLineOps<T>::difference_type rhs) {
return {lhs.value - rhs};
}
template <typename T>
BaseTemplatedRACIteratorOutOfLineOps<T>
operator+(typename BaseTemplatedRACIteratorOutOfLineOps<T>::difference_type lhs,
const BaseTemplatedRACIteratorOutOfLineOps<T> &rhs) {
return {rhs.value + lhs};
}
template <typename T>
struct InheritedTemplatedConstRACIteratorOutOfLineOps
: BaseTemplatedRACIteratorOutOfLineOps<T> {
using _super = BaseTemplatedRACIteratorOutOfLineOps<T>;
using _self = InheritedTemplatedConstRACIteratorOutOfLineOps<T>;
using iterator_category = std::random_access_iterator_tag;
using pointer = int *;
InheritedTemplatedConstRACIteratorOutOfLineOps(T value) : _super(value) {}
InheritedTemplatedConstRACIteratorOutOfLineOps(const _self &other) = default;
_self &operator++() {
_super::value++;
return *this;
}
_self operator++(int) {
auto tmp = _self(_super::value);
_super::value++;
return tmp;
}
void operator+=(typename _super::difference_type v) { _super::value += v; }
void operator-=(typename _super::difference_type v) { _super::value -= v; }
};
typedef InheritedTemplatedConstRACIteratorOutOfLineOps<int>
InheritedTemplatedConstRACIteratorOutOfLineOpsInt;
struct InputOutputIterator {
private:
int value;
public:
struct iterator_category : std::input_iterator_tag,
std::output_iterator_tag {};
using value_type = int;
using pointer = int *;
using reference = int &;
using const_reference = const int &;
using difference_type = int;
InputOutputIterator(int value) : value(value) {}
InputOutputIterator(const InputOutputIterator &other) = default;
const_reference operator*() const { return value; }
reference operator*() { return value; }
InputOutputIterator &operator++() {
value++;
return *this;
}
InputOutputIterator operator++(int) {
auto tmp = InputOutputIterator(value);
value++;
return tmp;
}
bool operator==(const InputOutputIterator &other) const {
return value == other.value;
}
bool operator!=(const InputOutputIterator &other) const {
return value != other.value;
}
};
struct InputOutputConstIterator {
private:
int *value;
public:
struct iterator_category : std::input_iterator_tag,
std::output_iterator_tag {};
using value_type = int;
using pointer = int *;
using reference = int &;
using difference_type = int;
InputOutputConstIterator(int *value) : value(value) {}
InputOutputConstIterator(const InputOutputConstIterator &other) = default;
reference operator*() const { return *value; }
InputOutputConstIterator &operator++() {
value++;
return *this;
}
InputOutputConstIterator operator++(int) {
auto tmp = InputOutputConstIterator(value);
value++;
return tmp;
}
bool operator==(const InputOutputConstIterator &other) const {
return value == other.value;
}
bool operator!=(const InputOutputConstIterator &other) const {
return value != other.value;
}
};
struct MutableRACIterator {
private:
int value;
public:
struct iterator_category : std::random_access_iterator_tag,
std::output_iterator_tag {};
using value_type = int;
using pointer = int *;
using reference = const int &;
using difference_type = int;
MutableRACIterator(int value) : value(value) {}
MutableRACIterator(const MutableRACIterator &other) = default;
const int &operator*() const { return value; }
int &operator*() { return value; }
MutableRACIterator &operator++() {
value++;
return *this;
}
MutableRACIterator operator++(int) {
auto tmp = MutableRACIterator(value);
value++;
return tmp;
}
void operator+=(difference_type v) { value += v; }
void operator-=(difference_type v) { value -= v; }
MutableRACIterator operator+(difference_type v) const {
return MutableRACIterator(value + v);
}
MutableRACIterator operator-(difference_type v) const {
return MutableRACIterator(value - v);
}
friend MutableRACIterator operator+(difference_type v,
const MutableRACIterator &it) {
return it + v;
}
int operator-(const MutableRACIterator &other) const {
return value - other.value;
}
bool operator<(const MutableRACIterator &other) const {
return value < other.value;
}
bool operator==(const MutableRACIterator &other) const {
return value == other.value;
}
bool operator!=(const MutableRACIterator &other) const {
return value != other.value;
}
};
/// clang::StmtIteratorBase
class ProtectedIteratorBase {
protected:
int value;
ProtectedIteratorBase() : value(0) {}
};
/// clang::StmtIteratorImpl
template <typename DERIVED>
class ProtectedIteratorImpl : public ProtectedIteratorBase {
protected:
ProtectedIteratorImpl(const ProtectedIteratorBase& RHS) : ProtectedIteratorBase(RHS) {}
public:
using iterator_category = std::forward_iterator_tag;
using value_type = int;
using difference_type = std::ptrdiff_t;
using pointer = int *;
using reference = int &;
ProtectedIteratorImpl() = default;
DERIVED& operator++() {
value++;
return static_cast<DERIVED&>(*this);
}
DERIVED operator++(int) {
DERIVED tmp = static_cast<DERIVED&>(*this);
operator++();
return tmp;
}
friend bool operator==(const DERIVED &LHS, const DERIVED &RHS) {
return LHS.value == RHS.value;
}
reference operator*() const {
return value;
}
};
/// StmtIterator
struct HasInheritedProtectedCopyConstructor : public ProtectedIteratorImpl<HasInheritedProtectedCopyConstructor> {
HasInheritedProtectedCopyConstructor() = default;
private:
HasInheritedProtectedCopyConstructor(const ProtectedIteratorBase &other)
: ProtectedIteratorImpl<HasInheritedProtectedCopyConstructor>(other) {}
};
#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_CUSTOM_ITERATOR_H
|