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 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
|
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2014 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#ifndef ETL_TUPLE_INCLUDED
#define ETL_TUPLE_INCLUDED
#include "platform.h"
#if ETL_NOT_USING_CPP11 && !defined(ETL_IN_UNIT_TEST)
#error NOT SUPPORTED FOR C++03 OR BELOW
#endif
#if ETL_USING_CPP11
#if ETL_USING_STL
#include <tuple>
#endif
#include "nth_type.h"
#include "type_traits.h"
#include "utility.h"
#include "functional.h"
#include "private/tuple_element.h"
#include "private/tuple_size.h"
namespace etl
{
//***************************************************************************
/// A tuple type
/// etl::tuple<TTypes...>
//***************************************************************************
template <typename... TTypes>
class tuple;
//***************************************************************************
/// Type trait to check if a type is an etl::tuple
/// Default implementation.
//***************************************************************************
template <typename T>
struct is_tuple : etl::false_type
{
};
//***************************************************************************
/// Type trait to check if a type is an etl::tuple
/// Specialisation for etl::tuple
//***************************************************************************
template <typename... TTypes>
struct is_tuple<etl::tuple<TTypes...>> : etl::true_type
{
};
namespace private_tuple
{
//***************************************************************************
/// Get the base of a tuple type whose head type is T.
//***************************************************************************
template <typename T, typename TTuple>
struct tuple_type_base;
// Specialisation for an empty tuple
template <typename T>
struct tuple_type_base<T, tuple<>>
{
using type = void;
};
// Recursive definition of the type.
template <typename T, typename THead, typename... TTail>
struct tuple_type_base<T, tuple<THead, TTail...>>
{
using type = etl::conditional_t<etl::is_same<T, THead>::value,
tuple<THead, TTail...>,
typename tuple_type_base<T, tuple<TTail...>>::type>;
};
// Get the base of a tuple type whose head type is T.
template <typename T, typename TTuple>
using tuple_type_base_t = typename tuple_type_base<T, TTuple>::type;
//***************************************************************************
/// ignore
/// An object of unspecified type such that any value can be assigned to it with no effect.
/// Intended for use with etl::tie when unpacking a etl::tuple, as a placeholder for the arguments that are not used.
/// https://en.cppreference.com/w/cpp/utility/tuple/ignore
//***************************************************************************
struct ignore_t
{
template <typename T>
ETL_CONSTEXPR ignore_t operator =(T&&) const ETL_NOEXCEPT
{
return *this;
}
};
}
//***************************************************************************
/// Empty tuple
//***************************************************************************
template<>
class tuple<>
{
public:
using value_type = void; ///< The type contained by this tuple.
using this_type = tuple<>; ///< The type of this tuple.
using base_type = void; ///< The type of the base tuple.
using index_sequence_type = etl::make_index_sequence<0>; ///< The index_sequence type for this tuple.
//*********************************
// No-op copy_assignment for the base case
//*********************************
ETL_CONSTEXPR14
void copy_assignment(const this_type& /*other*/)
{
}
//*********************************
// No-op forward_assignment for the base case
//*********************************
ETL_CONSTEXPR14
void forward_assignment(this_type&& /*other*/)
{
}
//*********************************
// No-op swap for the base case
//*********************************
ETL_CONSTEXPR14
void swap(this_type& /*other*/)
{
}
//*********************************
// Returns the size of the base case.
// Always zero.
//*********************************
ETL_NODISCARD
ETL_CONSTEXPR
static size_t size()
{
return 0U;
}
};
//***************************************************************************
/// Tuple
//***************************************************************************
template<typename THead, typename... TTail>
class tuple<THead, TTail...> : public tuple<TTail...>
{
private:
//*********************************
/// Helper function to calculate the number
/// of types from a type list.
//*********************************
template <typename... UTypes>
static constexpr size_t number_of_types()
{
return sizeof...(UTypes);
}
public:
//*********************************
/// Friends
//*********************************
template<typename... UTypes>
friend class tuple;
template <size_t Index, typename... TTypes>
ETL_CONSTEXPR14
friend etl::tuple_element_t<Index, etl::tuple<TTypes...>>& get(tuple<TTypes...>&);
template <size_t Index, typename... TTypes>
ETL_CONSTEXPR14
friend etl::tuple_element_t<Index, etl::tuple<TTypes...>>&& get(tuple<TTypes...>&&);
template <size_t Index, typename... TTypes>
ETL_CONSTEXPR14
friend const etl::tuple_element_t<Index, etl::tuple<TTypes...>>& get(const tuple<TTypes...>&);
template <size_t Index, typename... TTypes>
ETL_CONSTEXPR14
friend const etl::tuple_element_t<Index, etl::tuple<TTypes...>>&& get(const tuple<TTypes...>&&);
template <typename T, typename... TTypes>
ETL_CONSTEXPR14
friend T& get(tuple<TTypes...>&);
template <typename T, typename... TTypes>
ETL_CONSTEXPR14
friend T&& get(tuple<TTypes...>&&);
template <typename T, typename... TTypes>
ETL_CONSTEXPR14
friend const T& get(const tuple<TTypes...>&);
template <typename T, typename... TTypes>
ETL_CONSTEXPR14
friend const T&& get(const tuple<TTypes...>&&);
//*********************************
/// Types
//*********************************
using value_type = THead; ///< The type contained by this tuple.
using this_type = tuple<THead, TTail...>; ///< The type of this tuple.
using base_type = tuple<TTail...>; ///< The type of the base tuple.
using index_sequence_type = etl::make_index_sequence<number_of_types<THead, TTail...>()>; ///< The index_sequence type for this tuple.
//*********************************
/// Default constructor.
//*********************************
ETL_CONSTEXPR14
tuple()
: value()
{
}
//*********************************
/// Copy constructor.
//*********************************
ETL_CONSTEXPR14
tuple(const tuple<THead, TTail...>& other) = default;
//*********************************
/// Move constructor.
//*********************************
ETL_CONSTEXPR14
tuple(tuple<THead, TTail...>&& other) = default;
//*********************************
/// Copy assignment.
//*********************************
ETL_CONSTEXPR14
tuple& operator =(const tuple<THead, TTail...>& other) = default;
//*********************************
/// Move assignment.
//*********************************
ETL_CONSTEXPR14
tuple& operator =(tuple<THead, TTail...>&& other) = default;
//*********************************
/// Copy construct from lvalue reference tuple type.
/// Implicit conversion
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()) &&
(number_of_types<THead, TTail...>() >= 1U) &&
etl::is_convertible<UHead, THead>::value, int> = 0>
ETL_CONSTEXPR14
tuple(tuple<UHead, UTail...>& other)
: base_type(other.get_base())
, value(other.get_value())
{
}
//*********************************
/// Copy construct from lvalue reference tuple type.
/// Explicit conversion
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()) &&
(number_of_types<THead, TTail...>() >= 1U) &&
!etl::is_convertible<UHead, THead>::value, int> = 0>
ETL_CONSTEXPR14
explicit tuple(tuple<UHead, UTail...>& other)
: base_type(other.get_base())
, value(other.get_value())
{
}
//*********************************
/// Copy construct from const lvalue reference tuple type.
/// Implicit conversion
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()) &&
(number_of_types<THead, TTail...>() >= 1U) &&
etl::is_convertible<UHead, THead>::value, int> = 0>
ETL_CONSTEXPR14
tuple(const tuple<UHead, UTail...>& other)
: base_type(other.get_base())
, value(other.get_value())
{
}
//*********************************
/// Copy construct from const lvalue reference tuple type.
/// Explicit conversion
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()) &&
(number_of_types<THead, TTail...>() >= 1U) &&
!etl::is_convertible<UHead, THead>::value, int> = 0>
ETL_CONSTEXPR14
explicit tuple(const tuple<UHead, UTail...>& other)
: base_type(other.get_base())
, value(other.get_value())
{
}
//*********************************
/// Move construct from rvalue reference tuple type.
/// Implicit conversion
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()) &&
(number_of_types<THead, TTail...>() >= 1U) &&
etl::is_convertible<UHead, THead>::value, int> = 0>
ETL_CONSTEXPR14
tuple(tuple<UHead, UTail...>&& other)
: base_type(etl::forward<tuple<UTail...>>(other.get_base()))
, value(etl::forward<UHead>(other.get_value()))
{
}
//*********************************
/// Move construct from rvalue reference tuple type.
/// Explicit conversion
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()) &&
(number_of_types<THead, TTail...>() >= 1U) &&
!etl::is_convertible<UHead, THead>::value, int> = 0>
ETL_CONSTEXPR14
explicit tuple(tuple<UHead, UTail...>&& other)
: base_type(etl::forward<tuple<UTail...>>(other.get_base()))
, value(etl::forward<UHead>(other.get_value()))
{
}
//*********************************
/// Construct from const rvalue reference tuple type.
/// Implicit conversion
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()) &&
(number_of_types<THead, TTail...>() >= 1U) &&
etl::is_convertible<UHead, THead>::value, int> = 0>
ETL_CONSTEXPR14
tuple(const tuple<UHead, UTail...>&& other)
: base_type(other.get_base())
, value(other.get_value())
{
}
//*********************************
/// Construct from const rvalue reference tuple type.
/// Explicit conversion
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()) &&
(number_of_types<THead, TTail...>() >= 1U) &&
!etl::is_convertible<UHead, THead>::value, int> = 0>
ETL_CONSTEXPR14
explicit tuple(const tuple<UHead, UTail...>&& other)
: base_type(other.get_base())
, value(other.get_value())
{
}
//*********************************
/// Construct from arguments.
//*********************************
ETL_CONSTEXPR14
tuple(const THead& head, const TTail&... tail)
: base_type(tail...)
, value(head)
{
}
//*********************************
/// Construct from arguments.
/// Implicit conversion.
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<!is_tuple<etl::remove_reference_t<UHead>>::value &&
(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()) &&
(number_of_types<THead, TTail...>() >= 1U) &&
etl::is_convertible<UHead, THead>::value, int> = 0>
ETL_CONSTEXPR14
tuple(UHead&& head, UTail&&... tail) ETL_NOEXCEPT
: base_type(etl::forward<UTail>(tail)...)
, value(etl::forward<UHead>(head))
{
}
//*********************************
/// Construct from arguments.
/// explicit conversion.
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<!is_tuple<etl::remove_reference_t<UHead>>::value &&
(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()) &&
(number_of_types<THead, TTail...>() >= 1U) &&
!etl::is_convertible<UHead, THead>::value, int> = 0>
ETL_CONSTEXPR14
explicit tuple(UHead&& head, UTail&&... tail) ETL_NOEXCEPT
: base_type(etl::forward<UTail>(tail)...)
, value(etl::forward<UHead>(head))
{
}
//*********************************
/// Construct from lvalue reference pair.
/// Implicit conversion.
//*********************************
template <typename U1, typename U2, etl::enable_if_t<number_of_types<THead, TTail...>() == 2U &&
etl ::is_convertible<U1, THead>::value &&
etl ::is_convertible<U2, typename base_type::value_type>::value, int> = 0>
ETL_CONSTEXPR14
tuple(ETL_OR_STD::pair<U1, U2>& p) ETL_NOEXCEPT
: base_type(p.second)
, value(p.first)
{
}
//*********************************
/// Construct from lvalue reference pair.
/// Explicit conversion.
//*********************************
template <typename U1, typename U2, etl::enable_if_t<number_of_types<THead, TTail...>() == 2U &&
(!etl ::is_convertible<U1, THead>::value ||
!etl ::is_convertible<U2, typename base_type::value_type>::value), int> = 0>
ETL_CONSTEXPR14
explicit tuple(ETL_OR_STD::pair<U1, U2>& p) ETL_NOEXCEPT
: base_type(p.second)
, value(p.first)
{
}
//*********************************
/// Construct from const lvalue reference pair.
/// Implicit conversion.
//*********************************
template <typename U1, typename U2, etl::enable_if_t<number_of_types<THead, TTail...>() == 2U &&
etl ::is_convertible<U1, THead>::value &&
etl ::is_convertible<U2, typename base_type::value_type>::value, int> = 0>
ETL_CONSTEXPR14
tuple(const ETL_OR_STD::pair<U1, U2>& p) ETL_NOEXCEPT
: base_type(p.second)
, value(p.first)
{
}
//*********************************
/// Construct from const lvalue reference pair.
/// Explicit conversion.
//*********************************
template <typename U1, typename U2, etl::enable_if_t<number_of_types<THead, TTail...>() == 2U &&
(!etl ::is_convertible<U1, THead>::value ||
!etl ::is_convertible<U2, typename base_type::value_type>::value), int> = 0>
ETL_CONSTEXPR14
explicit tuple(const ETL_OR_STD::pair<U1, U2>& p) ETL_NOEXCEPT
: base_type(p.second)
, value(p.first)
{
}
//*********************************
/// Construct from rvalue reference pair.
/// Implicit conversion.
//*********************************
template <typename U1, typename U2, etl::enable_if_t<number_of_types<THead, TTail...>() == 2U &&
etl ::is_convertible<U1, THead>::value &&
etl ::is_convertible<U2, typename base_type::value_type>::value, int> = 0>
ETL_CONSTEXPR14
tuple(ETL_OR_STD::pair<U1, U2>&& p) ETL_NOEXCEPT
: base_type(etl::forward<U2>(p.second))
, value(etl::forward<U1>(p.first))
{
}
//*********************************
/// Construct from rvalue reference pair.
/// Explicit conversion.
//*********************************
template <typename U1, typename U2, etl::enable_if_t<number_of_types<THead, TTail...>() == 2U &&
(!etl ::is_convertible<U1, THead>::value ||
!etl ::is_convertible<U2, typename base_type::value_type>::value), int> = 0>
ETL_CONSTEXPR14
explicit tuple(ETL_OR_STD::pair<U1, U2>&& p) ETL_NOEXCEPT
: base_type(etl::forward<U2>(p.second))
, value(etl::forward<U1>(p.first))
{
}
//*********************************
/// Construct from const rvalue reference pair.
/// Implicit conversion.
//*********************************
template <typename U1, typename U2, etl::enable_if_t<number_of_types<THead, TTail...>() == 2U &&
etl ::is_convertible<U1, THead>::value &&
etl ::is_convertible<U2, typename base_type::value_type>::value, int> = 0>
ETL_CONSTEXPR14
tuple(const ETL_OR_STD::pair<U1, U2>&& p) ETL_NOEXCEPT
: base_type(etl::forward<U2>(p.second))
, value(etl::forward<U1>(p.first))
{
}
//*********************************
/// Construct from const rvalue reference pair.
/// Explicit conversion.
//*********************************
template <typename U1, typename U2, etl::enable_if_t<number_of_types<THead, TTail...>() == 2U &&
(!etl ::is_convertible<U1, THead>::value ||
!etl ::is_convertible<U2, typename base_type::value_type>::value), int> = 0>
ETL_CONSTEXPR14
explicit tuple(const ETL_OR_STD::pair<U1, U2>&& p) ETL_NOEXCEPT
: base_type(p.second)
, value(p.first)
{
}
//*********************************
/// Copy assign from other tuple type.
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()), int> = 0>
ETL_CONSTEXPR14
tuple& operator =(const tuple<UHead, UTail...>& other)
{
copy_assignment(other);
return *this;
}
//*********************************
/// Move assign from other tuple type.
//*********************************
template <typename UHead, typename... UTail, etl::enable_if_t<(number_of_types<THead, TTail...>() == number_of_types<UHead, UTail...>()), int> = 0>
ETL_CONSTEXPR14
tuple& operator =(tuple<UHead, UTail...>&& other)
{
forward_assignment(etl::forward<tuple<UHead, UTail...>>(other));
return *this;
}
//*********************************
/// Assign from lvalue pair tuple type.
//*********************************
template <typename U1, typename U2, size_t NTypes = number_of_types<THead, TTail...>, etl::enable_if_t<NTypes == 2U, int> = 0>
ETL_CONSTEXPR14
tuple& operator =(pair<U1, U2>& p)
{
get_value() = p.first;
get_base().get_value() = p.second;
return *this;
}
//*********************************
/// Assign from const lvalue pair tuple type.
//*********************************
template <typename U1, typename U2, size_t NTypes = number_of_types<THead, TTail...>, etl::enable_if_t<NTypes == 2U, int> = 0>
ETL_CONSTEXPR14
tuple& operator =(const pair<U1, U2>& p)
{
get_value() = p.first;
get_base().get_value() = p.second;
return *this;
}
//*********************************
/// Assign from rvalue pair tuple type.
//*********************************
template <typename U1, typename U2, size_t NTypes = number_of_types<THead, TTail...>, etl::enable_if_t<NTypes == 2U, int> = 0>
ETL_CONSTEXPR14
tuple& operator =(pair<U1, U2>&& p)
{
get_value() = etl::forward<U1>(p.first);
get_base().get_value() = etl::forward<U2>(p.second);
return *this;
}
//*********************************
/// Assign from const rvalue pair tuple type.
//*********************************
template <typename U1, typename U2, size_t NTypes = number_of_types<THead, TTail...>, etl::enable_if_t<NTypes == 2U, int> = 0>
ETL_CONSTEXPR14
tuple& operator =(const pair<U1, U2>&& p)
{
get_value() = etl::forward<U1>(p.first);
get_base().get_value() = etl::forward<U2>(p.second);
return *this;
}
//*********************************
/// Swaps this tuple with another.
//*********************************
ETL_CONSTEXPR14
void swap(this_type& other)
{
using ETL_OR_STD::swap;
// Swap the head
swap(get_value(), other.get_value());
auto& this_base = get_base();
auto& other_base = other.get_base();
// Recursively swap the tail by calling the base class's swap implementation.
this_base.swap(other_base);
}
//*********************************
/// Returns the number of elements in the tuple.
//*********************************
ETL_NODISCARD
constexpr
static size_t size()
{
return number_of_types<THead, TTail...>();
}
protected:
//*********************************
/// Returns a reference to the head value.
//*********************************
ETL_NODISCARD
ETL_CONSTEXPR14
THead& get_value()
{
return value;
}
//*********************************
/// Returns a const reference to the head value.
//*********************************
ETL_CONSTEXPR
const THead& get_value() const
{
return value;
}
//*********************************
/// Get a reference to the base class.
//*********************************
ETL_NODISCARD
ETL_CONSTEXPR14
base_type& get_base()
{
return static_cast<base_type&>(*this);
}
//*********************************
/// Get a const reference to the base class.
//*********************************
ETL_NODISCARD
ETL_CONSTEXPR14
const base_type& get_base() const
{
return static_cast<const base_type&>(*this);
}
//*********************************
/// Handles copy assignment from another tuple.
//*********************************
template <typename UHead, typename... UTail>
ETL_CONSTEXPR14
void copy_assignment(const tuple<UHead, UTail...>& other)
{
// Assign the head
this->value = other.get_value();
// Get the base classes
auto& this_base = get_base();
const auto& other_base = other.get_base();
// Recursively assign the tail by calling the base class's assignment implementation
this_base.copy_assignment(other_base);
}
//*********************************
/// Handles move assignment from another tuple.
//*********************************
template <typename UHead, typename... UTail>
ETL_CONSTEXPR14
void forward_assignment(tuple<UHead, UTail...>&& other)
{
// Assign the head
this->value = etl::forward<UHead>(other.get_value());
auto& this_base = get_base();
auto&& other_base = other.get_base();
// Recursively assign the tail by calling the base class's move assignment implementation
this_base.forward_assignment(etl::forward<tuple<UTail...>>(other_base));
}
private:
THead value;
};
#if ETL_USING_CPP17
//***************************************************************************
/// Template deduction guideline from variadic arguments.
//***************************************************************************
template <typename... TArgs>
tuple(TArgs... args) -> tuple<TArgs...>;
//***************************************************************************
/// Template deduction guideline from pair.
//***************************************************************************
template <typename T1, typename T2>
tuple(ETL_OR_STD::pair<T1, T2>) -> tuple<T1, T2>;
#endif
//***************************************************************************
/// Gets the element type at the index in the tuple.
//***************************************************************************
template<size_t Index, typename... TTypes>
struct tuple_element<Index, etl::tuple<TTypes...>>
{
using type = etl::nth_type_t<Index, TTypes...>;
};
//***************************************************************************
/// Gets the size of the tuple.
//***************************************************************************
template <typename... TTypes>
struct tuple_size<etl::tuple<TTypes...>>
: etl::integral_constant<size_t, sizeof...(TTypes)>
{
};
//***************************************************************************
/// Gets the common type of a tuple.
//***************************************************************************
template<typename... Types>
struct common_type<etl::tuple<Types...>>
{
using type = etl::common_type_t<Types...>;
};
//***************************************************************************
/// Extracts the element at Index from the tuple.
/// Index must be an integer value in sizeof...(TTypes)).
/// Returns a reference.
//***************************************************************************
template <size_t Index, typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
etl::tuple_element_t<Index, etl::tuple<TTypes...>>& get(tuple<TTypes...>& t)
{
ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get<Index> - Index out of range");
// Get the type at this index.
using tuple_type = etl::nth_base_t<Index, tuple<TTypes...>>&;
// Cast the tuple to the selected type and get the value.
return static_cast<tuple_type>(t).get_value();
}
//***************************************************************************
/// Extracts the element at Index from the tuple.
/// Index must be an integer value in [?0?, sizeof...(TTypes)).
/// Returns a const reference.
//***************************************************************************
template <size_t Index, typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
const etl::tuple_element_t<Index, etl::tuple<TTypes...>>& get(const tuple<TTypes...>& t)
{
ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get<Index> - Index out of range");
// Get the type at this index.
using tuple_type = const etl::nth_base_t<Index, tuple<TTypes...>>&;
// Cast the tuple to the selected type and get the value.
return static_cast<tuple_type>(t).get_value();
}
//***************************************************************************
/// Extracts the element at Index from the tuple.
/// Index must be an integer value in [?0?, sizeof...(TTypes)).
/// Returns an rvalue reference.
//***************************************************************************
template <size_t Index, typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
etl::tuple_element_t<Index, etl::tuple<TTypes...>>&& get(tuple<TTypes...>&& t)
{
ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get<Index> - Index out of range");
// Get the type at this index.
using tuple_type = etl::nth_base_t<Index, tuple<TTypes...>>&&;
// Cast the tuple to the selected type and get the value.
return etl::move(static_cast<tuple_type>(t).get_value());
}
//***************************************************************************
/// Extracts the element at Index from the tuple.
/// Index must be an integer value in [?0?, sizeof...(TTypes)).
/// Returns a const rvalue reference.
//***************************************************************************
template <size_t Index, typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
const etl::tuple_element_t<Index, etl::tuple<TTypes...>>&& get(const tuple<TTypes...>&& t)
{
ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get<Index> - Index out of range");
// Get the type at this index.
using tuple_type = const etl::nth_base_t<Index, etl::tuple<TTypes...>>&&;
// Cast the tuple to the selected type and get the value.
return etl::move(static_cast<tuple_type>(t).get_value());
}
//***************************************************************************
/// Extracts the element with type T from the tuple.
/// Static asserts if the tuple contain more than one T, or does not contain a T element.
/// Returns a reference.
//***************************************************************************
template <typename T, typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
T& get(tuple<TTypes...>& t)
{
ETL_STATIC_ASSERT(!(etl::has_duplicates_of<T, TTypes...>::value), "etl::get<Type> - Tuple contains duplicate instances of T");
ETL_STATIC_ASSERT((etl::is_one_of<T, TTypes...>::value), "etl::get<Type> - Tuple does not contain the specified type");
// Get the tuple base type that contains a T
using tuple_type = etl::private_tuple::tuple_type_base_t<T, tuple<TTypes...>>&;
// Cast the tuple to the selected type and get the value.
return static_cast<tuple_type>(t).get_value();
}
//***************************************************************************
/// Extracts the element with type T from the tuple.
/// Static asserts if the tuple contain more than one T, or does not contain a T element.
/// Returns a const reference.
//***************************************************************************
template <typename T, typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
const T& get(const tuple<TTypes...>& t)
{
ETL_STATIC_ASSERT(!(etl::has_duplicates_of<T, TTypes...>::value), "etl::get<Type> - Tuple contains duplicate instances of T");
ETL_STATIC_ASSERT((etl::is_one_of<T, TTypes...>::value), "etl::get<Type> - Tuple does not contain the specified type");
// Get the tuple base type that contains a T
using tuple_type = const etl::private_tuple::tuple_type_base_t<T, tuple<TTypes...>>&;
// Cast the tuple to the selected type and get the value.
return static_cast<tuple_type>(t).get_value();
}
//***************************************************************************
/// Extracts the element with type T from the tuple.
/// Static asserts if the tuple contain more than one T, or does not contain a T element.
/// Returns an rvalue reference.
//***************************************************************************
template <typename T, typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
T&& get(tuple<TTypes...>&& t)
{
ETL_STATIC_ASSERT(!(etl::has_duplicates_of<T, TTypes...>::value), "etl::get<Type> - Tuple contains duplicate instances of T");
ETL_STATIC_ASSERT((etl::is_one_of<T, TTypes...>::value), "etl::get<Type> - Tuple does not contain the specified type");
// Get the tuple base type that contains a T
using tuple_type = etl::private_tuple::tuple_type_base_t<T, tuple<TTypes...>>&&;
// Cast the tuple to the selected type and get the value.
return etl::move(static_cast<tuple_type>(t).get_value());
}
//***************************************************************************
/// Extracts the element with type T from the tuple.
/// Static asserts if the tuple contain more than one T, or does not contain a T element.
/// Returns a const rvalue reference.
//***************************************************************************
template <typename T, typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
const T&& get(const tuple<TTypes...>&& t)
{
ETL_STATIC_ASSERT(!(etl::has_duplicates_of<T, TTypes...>::value), "etl::get<Type> - Tuple contains duplicate instances of T");
ETL_STATIC_ASSERT((etl::is_one_of<T, TTypes...>::value), "etl::get<Type> - Tuple does not contain the specified type");
// Get the tuple base type that contains a T
using tuple_type = const etl::private_tuple::tuple_type_base_t<T, tuple<TTypes...>>&&;
// Cast the tuple to the selected type and get the value.
return etl::move(static_cast<tuple_type>(t).get_value());
}
#if ETL_USING_CPP17
inline constexpr private_tuple::ignore_t ignore;
#else
static constexpr private_tuple::ignore_t ignore;
#endif
//***************************************************************************
/// Creates a tuple of references to the provided arguments.
//***************************************************************************
template <typename... TTypes>
ETL_CONSTEXPR
etl::tuple<TTypes&...> tie(TTypes&... args)
{
return { args... };
}
//***************************************************************************
// Creates a tuple from the provided arguments.
//***************************************************************************
template <typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
etl::tuple<etl::unwrap_ref_decay_t<TTypes>...> make_tuple(TTypes&&... args)
{
return etl::tuple<unwrap_ref_decay_t<TTypes>...>(etl::forward<TTypes>(args)...);
}
//***************************************************************************
/// Creates a new tuple by selecting elements from another, given a run time index sequence.
/// Static asserts if the number of indices does not match the tuple size.
//***************************************************************************
template <typename TTuple, size_t... Indices>
ETL_NODISCARD
ETL_CONSTEXPR14
auto select_from_tuple(TTuple&& tuple, etl::index_sequence<Indices...>)
-> etl::tuple<etl::tuple_element_t<Indices, etl::decay_t<TTuple>>...>
{
ETL_STATIC_ASSERT(sizeof...(Indices) <= etl::tuple_size<etl::decay_t<TTuple>>::value, "Number of indices is greater than the tuple size");
return etl::make_tuple(etl::forward<etl::tuple_element_t<Indices, etl::decay_t<TTuple>>>(etl::get<Indices>(etl::forward<TTuple>(tuple)))...);
}
//***************************************************************************
/// Creates a new tuple by selecting elements from another, given a template parameter index sequence.
/// Static asserts if the number of indices does not match the tuple size.
//***************************************************************************
template <size_t... Indices, typename TTuple>
ETL_NODISCARD
ETL_CONSTEXPR14
auto select_from_tuple(TTuple&& tuple)
-> etl::tuple<etl::tuple_element_t<Indices, etl::decay_t<TTuple>>...>
{
return select_from_tuple(etl::forward<TTuple>(tuple), etl::index_sequence<Indices...>{});
}
//***************************************************************************
/// Forwards the arguments as a tuple.
//***************************************************************************
template <typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
etl::tuple<TTypes&&...> forward_as_tuple(TTypes&&... args)
{
return tuple<TTypes&&...>(etl::forward<TTypes>(args)...);
}
namespace private_tuple
{
//**********************************
// Helper to concatenate two tuples
//**********************************
template <typename Tuple1, typename Tuple2, size_t... Index1, size_t... Index2>
ETL_CONSTEXPR14
auto tuple_cat_impl(Tuple1&& t1, etl::index_sequence<Index1...>, Tuple2&& t2, etl::index_sequence<Index2...>)
-> etl::tuple<etl::tuple_element_t<Index1, etl::decay_t<Tuple1>>..., etl::tuple_element_t<Index2, etl::decay_t<Tuple2>>...>
{
return etl::tuple<etl::tuple_element_t<Index1, etl::decay_t<Tuple1>>...,
etl::tuple_element_t<Index2, etl::decay_t<Tuple2>>...>
(etl::get<Index1>(etl::forward<Tuple1>(t1))..., etl::get<Index2>(etl::forward<Tuple2>(t2))...);
}
}
//***************************************************************************
/// Base case for concatenating one tuple
//***************************************************************************
template <typename Tuple>
ETL_NODISCARD
ETL_CONSTEXPR14
auto tuple_cat(Tuple&& t) -> Tuple
{
return etl::forward<Tuple>(t);
}
//***************************************************************************
/// Recursive case for concatenating multiple tuples
//***************************************************************************
template <typename Tuple1, typename Tuple2, typename... Tuples>
ETL_NODISCARD
ETL_CONSTEXPR14
auto tuple_cat(Tuple1&& t1, Tuple2&& t2, Tuples&&... ts)
-> decltype(private_tuple::tuple_cat_impl(etl::forward<Tuple1>(t1),
etl::make_index_sequence<etl::tuple_size<etl::decay_t<Tuple1>>::value>{},
etl::forward<Tuple2>(t2),
etl::make_index_sequence<etl::tuple_size<etl::decay_t<Tuple2>>::value>{}))
{
auto concatenated = private_tuple::tuple_cat_impl(etl::forward<Tuple1>(t1),
etl::make_index_sequence<etl::tuple_size<etl::decay_t<Tuple1>>::value>{},
etl::forward<Tuple2>(t2),
etl::make_index_sequence<etl::tuple_size<etl::decay_t<Tuple2>>::value>{});
return tuple_cat(etl::move(concatenated), etl::forward<Tuples>(ts)...);
}
#if ETL_USING_STL
//***************************************************************************
// Tuple conversion functions.
// From ETL to STL
//***************************************************************************
namespace private_tuple
{
///*********************************
template<typename TEtl_Tuple, size_t... Indices>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_std_impl(const TEtl_Tuple& etl_tuple, etl::index_sequence<Indices...>)
-> std::tuple<typename etl::tuple_element_t<Indices, TEtl_Tuple>...>
{
return std::tuple<etl::tuple_element_t<Indices, TEtl_Tuple>...>(etl::get<Indices>(etl_tuple)...);
}
///*********************************
template<typename TEtl_Tuple, size_t... Indices>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_std_impl(TEtl_Tuple&& etl_tuple, etl::index_sequence<Indices...>)
-> std::tuple<etl::tuple_element_t<Indices, TEtl_Tuple>...>
{
return std::tuple<etl::tuple_element_t<Indices, TEtl_Tuple>...>(etl::move(etl::get<Indices>(etl_tuple))...);
}
}
//***************************************************************************
/// Converts an etl::tuple to a std::tuple.
//***************************************************************************
template<typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_std(const etl::tuple<TTypes...>& etl_tuple)
-> std::tuple<etl::decay_t<TTypes>...>
{
return private_tuple::to_std_impl(etl_tuple, etl::make_index_sequence_for<TTypes...>());
}
//***************************************************************************
/// Converts an etl::tuple to a std::tuple.
//***************************************************************************
template<typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_std(etl::tuple<TTypes...>&& etl_tuple)
-> std::tuple<etl::decay_t<TTypes>...>
{
return private_tuple::to_std_impl(etl::move(etl_tuple), etl::make_index_sequence_for<TTypes...>());
}
//***************************************************************************
/// Tuple conversion functions.
/// From STL to ETL
//***************************************************************************
namespace private_tuple
{
///*********************************
template<typename TStd_Tuple, size_t... Indices>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_etl_impl(const TStd_Tuple& std_tuple, etl::index_sequence<Indices...>)
-> etl::tuple<typename std::tuple_element<Indices, TStd_Tuple>::type...>
{
return etl::tuple<typename std::tuple_element<Indices, TStd_Tuple>::type...>(std::get<Indices>(std_tuple)...);
}
///*********************************
template<typename TStd_Tuple, size_t... Indices>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_etl_impl(TStd_Tuple&& std_tuple, etl::index_sequence<Indices...>)
-> etl::tuple<typename std::tuple_element<Indices, TStd_Tuple>::type...>
{
return etl::tuple<typename std::tuple_element<Indices, TStd_Tuple>::type...>(std::move(std::get<Indices>(std_tuple))...);
}
}
//***************************************************************************
/// Converts a std::tuple to an etl::tuple.
//***************************************************************************
template<typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_etl(const std::tuple<TTypes...>& std_tuple)
-> etl::tuple<etl::decay_t<TTypes>...>
{
return private_tuple::to_etl_impl(std_tuple, etl::make_index_sequence_for<TTypes...>());
}
//***************************************************************************
/// Converts a std::tuple to an etl::tuple.
//***************************************************************************
template<typename... TTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_etl(std::tuple<TTypes...>&& std_tuple)
-> etl::tuple<etl::decay_t<TTypes>...>
{
return private_tuple::to_etl_impl(etl::move(std_tuple), etl::make_index_sequence_for<TTypes...>());
}
#endif
namespace private_tuple
{
//***************************************************************************
/// Equality
//***************************************************************************
// When there are no indices left to compare.
template <typename TTuple1, typename TTuple2>
ETL_NODISCARD
ETL_CONSTEXPR14
bool tuple_equality(const TTuple1& /*lhs*/, const TTuple2& /*rhs*/, etl::index_sequence<>)
{
return true;
}
// Recursive case: compare the current element and recurse.
template <typename TTuple1, typename TTuple2, size_t Index, size_t... Indices>
ETL_NODISCARD
ETL_CONSTEXPR14
bool tuple_equality(const TTuple1& lhs, const TTuple2& rhs, etl::index_sequence<Index, Indices...>)
{
return etl::get<Index>(lhs) == etl::get<Index>(rhs) && tuple_equality(lhs, rhs, etl::index_sequence<Indices...>{});
}
//***************************************************************************
/// Less than
//***************************************************************************
// When there are no indices left to compare.
template <typename TTuple1, typename TTuple2>
ETL_NODISCARD
ETL_CONSTEXPR14
bool tuple_less_than(const TTuple1& /*lhs*/, const TTuple2& /*rhs*/, etl::index_sequence<>)
{
return false;
}
// Recursively compare the current element and the rest.
template <typename TTuple1, typename TTuple2, size_t Index, size_t... Indices>
ETL_NODISCARD
ETL_CONSTEXPR14
bool tuple_less_than(const TTuple1& lhs, const TTuple2& rhs, etl::index_sequence<Index, Indices...>)
{
if (get<Index>(lhs) < get<Index>(rhs))
{
return true;
}
if (get<Index>(rhs) < get<Index>(lhs))
{
return false;
}
return tuple_less_than(lhs, rhs, etl::index_sequence<Indices...>{});
}
}
//***************************************************************************
/// Equality operator.
//***************************************************************************
template <typename... TTypes, typename... UTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
bool operator ==(const etl::tuple<TTypes...>& lhs,
const etl::tuple<UTypes...>& rhs)
{
ETL_STATIC_ASSERT(sizeof...(TTypes) == sizeof...(UTypes), "Cannot compare tuples of different sizes");
// Compare each element of the tuples.
return private_tuple::tuple_equality(lhs, rhs, etl::make_index_sequence<etl::tuple<TTypes...>::size()>{});
}
//***************************************************************************
/// Inequality operator.
//***************************************************************************
template <typename... TTypes, typename... UTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
bool operator !=(const etl::tuple<TTypes...>& lhs,
const etl::tuple<UTypes...>& rhs)
{
return !(lhs == rhs);
}
//***************************************************************************
/// Less than operator.
//***************************************************************************
template <typename... TTypes, typename... UTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
bool operator <(const etl::tuple<TTypes...>& lhs,
const etl::tuple<UTypes...>& rhs)
{
ETL_STATIC_ASSERT(sizeof...(TTypes) == sizeof...(UTypes), "Cannot compare tuples of different sizes");
// Compare the elements.
return private_tuple::tuple_less_than(lhs, rhs, etl::make_index_sequence<etl::tuple<TTypes...>::size()>{});
}
//***************************************************************************
/// Less than or equals operator.
//***************************************************************************
template <typename... TTypes, typename... UTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
bool operator <=(const etl::tuple<TTypes...>& lhs,
const etl::tuple<UTypes...>& rhs)
{
return !(rhs < lhs);
}
//***************************************************************************
/// Greater than operator.
//***************************************************************************
template <typename... TTypes, typename... UTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
bool operator >(const etl::tuple<TTypes...>& lhs,
const etl::tuple<UTypes...>& rhs)
{
return (rhs < lhs);
}
//***************************************************************************
/// Greater than or equals operator.
//***************************************************************************
template <typename... TTypes, typename... UTypes>
ETL_NODISCARD
ETL_CONSTEXPR14
bool operator >=(const etl::tuple<TTypes...>& lhs,
const etl::tuple<UTypes...>& rhs)
{
return !(lhs < rhs);
}
//***************************************************************************
/// Swap two tuples.
//***************************************************************************
template <typename... TTypes>
ETL_CONSTEXPR14
void swap(etl::tuple<TTypes...>& lhs, etl::tuple<TTypes...>& rhs)
{
lhs.swap(rhs);
}
}
namespace std
{
#if ETL_NOT_USING_STL && !((defined(ETL_DEVELOPMENT_OS_APPLE) || \
(ETL_COMPILER_FULL_VERSION >= 190000)) && defined(ETL_COMPILER_CLANG))
template <typename T>
struct tuple_size;
template <size_t Index, typename TType>
struct tuple_element;
#endif
//***************************************************************************
/// Specialisation of tuple_size to allow the use of C++ structured bindings.
//***************************************************************************
template <typename... Types>
struct tuple_size<etl::tuple<Types...>> : etl::integral_constant<size_t, sizeof...(Types)>
{
};
//***************************************************************************
/// Specialisation of tuple_element to allow the use of C++ structured bindings.
//***************************************************************************
template <size_t Index, typename... Types>
struct tuple_element<Index, etl::tuple<Types...>>
{
using type = typename etl::nth_type_t<Index, Types...>;
};
}
#endif
#endif
|