/usr/include/CLHEP/Utility/type_traits.h is in libclhep-dev 2.1.2.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 | #ifndef CLHEP_TYPE_TRAITS_H
#define CLHEP_TYPE_TRAITS_H
// ======================================================================
//
// type_traits - selected C++0X metaprogramming constructs
//
// Author: W. E. Brown; 2010-03-05
//
// ======================================================================
#include "CLHEP/Utility/defs.h"
#include <memory> // for auto_ptr
#if defined(__GXX_EXPERIMENTAL_CXX0X__)
# define CLHEP_HAS_RVALUE_REFERENCE
#else
# define CLHEP_NO_RVALUE_REFERENCE
#endif
namespace CLHEP {
// ----------------------------------------------------------------------
// Contents:
// ----------------------------------------------------------------------
// helper class:
template< typename T, T v > struct integral_constant;
typedef integral_constant<bool, true > true_type;
typedef integral_constant<bool, false > false_type;
// primary type categories:
template< typename T > struct is_void;
template< typename T > struct is_integral;
template< typename T > struct is_floating_point;
template< typename T > struct is_array;
template< typename T > struct is_pointer;
template< typename T > struct is_lvalue_reference;
template< typename T > struct is_rvalue_reference;
template< typename T > struct is_member_object_pointer;
template< typename T > struct is_member_function_pointer;
template< typename T > struct is_enum;
template< typename T > struct is_union;
template< typename T > struct is_class;
template< typename T > struct is_function;
// composite type categories:
template< typename T > struct is_reference;
template< typename T > struct is_arithmetic;
template< typename T > struct is_fundamental;
template< typename T > struct is_object;
template< typename T > struct is_scalar;
template< typename T > struct is_compound;
template< typename T > struct is_member_pointer;
// type properties:
template< typename T > struct is_const;
template< typename T > struct is_volatile;
#if 0
template< typename T > struct is_trivial;
template< typename T > struct is_trivially_copyable;
template< typename T > struct is_standard_layout;
template< typename T > struct is_pod;
template< typename T > struct is_literal_type;
template< typename T > struct is_empty;
template< typename T > struct is_polymorphic;
#endif // 0
template< typename T > struct is_abstract;
#if 0
template< typename T, typename... Args > struct is_constructible;
template< typename T, typename... Args > struct is_nothrow_constructible;
template< typename T > struct has_default_constructor;
template< typename T > struct has_copy_constructor;
template< typename T > struct has_copy_assign;
template< typename T > struct has_move_constructor;
template< typename T > struct has_move_assign;
template< typename T > struct has_trivial_default_constructor;
template< typename T > struct has_trivial_copy_constructor;
template< typename T > struct has_trivial_move_constructor;
template< typename T > struct has_trivial_copy_assign;
template< typename T > struct has_trivial_move_assign;
template< typename T > struct has_trivial_destructor;
template< typename T > struct has_nothrow_default_constructor;
template< typename T > struct has_nothrow_copy_constructor;
template< typename T > struct has_nothrow_move_constructor;
template< typename T > struct has_nothrow_copy_assign;
template< typename T > struct has_nothrow_move_assign;
template< typename T > struct has_virtual_destructor;
#endif // 0
template< typename T > struct is_signed;
template< typename T > struct is_unsigned;
#if 0
template< typename T > struct alignment_of;
#endif // 0
template< typename T > struct rank;
template< typename T, unsigned I = 0 > struct extent;
// type relations:
template< typename T, typename U > struct is_same;
#if 0
template< typename Base, typename Derived > struct is_base_of;
#endif // 0
template< typename From, typename To > struct is_convertible;
#if 0
template< typename From, typename To > struct is_explicitly_convertible;
#endif // 0
// const-volatile modifications:
template< typename T > struct remove_const;
template< typename T > struct remove_volatile;
template< typename T > struct remove_cv;
template< typename T > struct add_const;
template< typename T > struct add_volatile;
template< typename T > struct add_cv;
// reference modifications:
template< typename T > struct remove_reference;
template< typename T > struct add_lvalue_reference;
template< typename T > struct add_rvalue_reference;
// sign modifications:
#if 0
template< typename T > struct make_signed;
template< typename T > struct make_unsigned;
#endif // 0
// array modifications:
template< typename T > struct remove_extent;
template< typename T > struct remove_all_extents;
// pointer modifications:
template< typename T > struct remove_pointer;
template< typename T > struct add_pointer;
// other transformations:
#if 0
template< std::size_t Len, std::size_t Align > struct aligned_storage;
template< std::size_t Len, typename... Types > struct aligned_union;
template< typename T > struct decay;
#endif // 0
template< bool, typename T = void > struct enable_if;
template< bool, typename T, typename F > struct conditional;
#if 0
template< typename... T > struct common_type;
template< typename T > struct underlying_type;
template< typename > typename result_of; // undefined
template< typename F, typename... ArgTypes > typename result_of<F(ArgTypes...)>;
#endif // 0
// non-standard (but useful) extensions:
template< typename From, typename To > struct is_ptr_convertible;
template< typename From, typename To, typename R=void > struct enable_if_convertible;
template< typename From, typename To, typename R=void > struct enable_if_ptr_convertible;
template< typename P, typename R=void > struct enable_if_auto_ptr;
// ----------------------------------------------------------------------
// integral_constant - a helper class, useful in its own right
// ----------------------------------------------------------------------
template< typename T, T v >
struct integral_constant
{
typedef T value_type;
typedef integral_constant<T,v> type;
static value_type const value = v;
operator value_type() { return value; }
}; // integral_constant<,>
// ----------------------------------------------------------------------
// yes_t, no_t - unimplemented types with distinct sizeof
// ----------------------------------------------------------------------
namespace tt {
typedef char (& yes_t); // ref to char
typedef char (& no_t ) [2]; // ref to 2-char array
} // namespace tt
// ----------------------------------------------------------------------
// primary<,> - type classification helper
// ----------------------------------------------------------------------
namespace tt {
enum primary_code
{ _unknown = 0u
, _void = 1u << 0
, _integral = 1u << 1
, _floating_point = 1u << 2
, _array = 1u << 3
, _pointer = 1u << 4
, _lvalue_reference = 1u << 5
, _rvalue_reference = 1u << 6
, _member_object_pointer = 1u << 7
, _member_function_pointer = 1u << 8
, _enum = 1u << 9
, _union = 1u << 10 // Help, compiler!
, _class = 1u << 11
, _function = 1u << 12
}; // primary_code
// Helpers to recognize classes:
template< typename U > yes_t isAclass( void(U::*)() );
template< typename U > no_t isAclass( ... );
// Helpers to recognize functions:
template< typename U >
no_t isAfunction( U(*)[1] ); // arrays of non-{fctn/ref/void}s
template< typename U >
yes_t isAfunction( ... );
// encode via helpers or by elimination:
// enum
// union // need help, compiler!
// class
// function
template< typename T >
struct encode
{
static primary_code const value
= ( sizeof(isAclass <T>(0)) == sizeof(yes_t) ) ? _class
: ( ( sizeof(isAfunction<T>(0)) == sizeof(yes_t) ) ? _function
: /* by elimination */ _enum
);
}; // encode<>
// encode cv-qualified type:
template< typename T >
struct encode<T const> : public encode<T> { };
template< typename T >
struct encode<T volatile> : public encode<T> { };
template< typename T >
struct encode<T const volatile> : public encode<T> { };
// encode array:
template< typename T >
struct encode<T[]>
{ static primary_code const value = _array; };
template< typename T >
struct encode<T const[]>
{ static primary_code const value = _array; };
template< typename T >
struct encode<T volatile[]>
{ static primary_code const value = _array; };
template< typename T >
struct encode<T const volatile[]>
{ static primary_code const value = _array; };
template< typename T, unsigned N >
struct encode<T[N]>
{ static primary_code const value = _array; };
template< typename T, unsigned N >
struct encode<T const[N]>
{ static primary_code const value = _array; };
template< typename T, unsigned N >
struct encode<T volatile[N]>
{ static primary_code const value = _array; };
template< typename T, unsigned N >
struct encode<T const volatile[N]>
{ static primary_code const value = _array; };
// encode floating_point:
template<>
struct encode<float>
{ static primary_code const value = _floating_point; };
template<>
struct encode<double>
{ static primary_code const value = _floating_point; };
template<>
struct encode<long double>
{ static primary_code const value = _floating_point; };
// encode integral:
template<>
struct encode<bool>
{ static primary_code const value = _integral; };
template<>
struct encode<signed char>
{ static primary_code const value = _integral; };
template<>
struct encode<char>
{ static primary_code const value = _integral; };
template<>
struct encode<unsigned char>
{ static primary_code const value = _integral; };
#if 0
template<>
struct encode<wchar_t>
{ static primary_code const value = _integral; };
#endif
template<>
struct encode<short>
{ static primary_code const value = _integral; };
template<>
struct encode<unsigned short>
{ static primary_code const value = _integral; };
template<>
struct encode<int>
{ static primary_code const value = _integral; };
template<>
struct encode<unsigned int>
{ static primary_code const value = _integral; };
template<>
struct encode<long>
{ static primary_code const value = _integral; };
template<>
struct encode<unsigned long>
{ static primary_code const value = _integral; };
// encode member_function_pointer:
template< typename T, typename C >
struct encode<T (C::*)()>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C >
struct encode<T (C::*)() const>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C >
struct encode<T (C::*)() volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C >
struct encode<T (C::*)() const volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1 >
struct encode<T (C::*)(A1)>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1 >
struct encode<T (C::*)(A1) const>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1 >
struct encode<T (C::*)(A1) volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1 >
struct encode<T (C::*)(A1) const volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2 >
struct encode<T (C::*)(A1,A2)>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2 >
struct encode<T (C::*)(A1,A2) const>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2 >
struct encode<T (C::*)(A1,A2) volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2 >
struct encode<T (C::*)(A1,A2) const volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3 >
struct encode<T (C::*)(A1,A2,A3)>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3 >
struct encode<T (C::*)(A1,A2,A3) const>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3 >
struct encode<T (C::*)(A1,A2,A3) volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3 >
struct encode<T (C::*)(A1,A2,A3) const volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3, typename A4 >
struct encode<T (C::*)(A1,A2,A3,A4)>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3, typename A4 >
struct encode<T (C::*)(A1,A2,A3,A4) const>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3, typename A4 >
struct encode<T (C::*)(A1,A2,A3,A4) volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3, typename A4 >
struct encode<T (C::*)(A1,A2,A3,A4) const volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3, typename A4, typename A5 >
struct encode<T (C::*)(A1,A2,A3,A4,A5)>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3, typename A4, typename A5 >
struct encode<T (C::*)(A1,A2,A3,A4,A5) const>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3, typename A4, typename A5 >
struct encode<T (C::*)(A1,A2,A3,A4,A5) volatile>
{ static primary_code const value = _member_function_pointer; };
template< typename T, typename C
, typename A1, typename A2, typename A3, typename A4, typename A5 >
struct encode<T (C::*)(A1,A2,A3,A4,A5) const volatile>
{ static primary_code const value = _member_function_pointer; };
// encode member_object_pointer:
template< typename T, typename C >
struct encode<T C::*>
{ static primary_code const value = _member_object_pointer; };
// encode pointer:
template< typename T >
struct encode<T *>
{ static primary_code const value = _pointer; };
// encode lvalue_reference:
template< typename T >
struct encode<T &>
{ static primary_code const value = _lvalue_reference; };
// encode rvalue_reference:
#if defined(CLHEP_HAS_RVALUE_REFERENCE)
template< typename T >
struct encode<T&&>
{ static primary_code const value = _rvalue_reference; };
#endif // CLHEP_HAS_RVALUE_REFERENCE
// encode void:
template<>
struct encode<void>
{ static primary_code const value = _void; };
// apply encoding:
template< typename T, unsigned int p >
struct primary : integral_constant<bool, bool(p & encode<T>::value)> { };
} // namespace tt
// ----------------------------------------------------------------------
// is_void - metaprogramming type trait detecting void types
// ----------------------------------------------------------------------
template< typename T >
struct is_void
: public tt::primary<T, tt::_void > { };
// ----------------------------------------------------------------------
// is_integral - metaprogramming type trait detecting integer types
// ----------------------------------------------------------------------
template< typename T >
struct is_integral
: public tt::primary<T, tt::_integral > { };
// ----------------------------------------------------------------------
// is_floating_point - metaprogramming type trait detecting real types
// ----------------------------------------------------------------------
template< typename T >
struct is_floating_point
: public tt::primary<T, tt::_floating_point > { };
// ----------------------------------------------------------------------
// is_array - metaprogramming type trait detecting T[...] types
// ----------------------------------------------------------------------
template< typename T >
struct is_array
: public tt::primary<T, tt::_array > { };
// ----------------------------------------------------------------------
// is_pointer - metaprogramming type trait detecting T* types
// ----------------------------------------------------------------------
template< typename T >
struct is_pointer
: public tt::primary<T, tt::_pointer > { };
// ----------------------------------------------------------------------
// is_lvalue_reference - metaprogramming type trait detecting T& types
// ----------------------------------------------------------------------
template< typename T >
struct is_lvalue_reference
: public tt::primary<T, tt::_lvalue_reference > { };
// ----------------------------------------------------------------------
// is_rvalue_reference - metaprogramming type trait detecting T&& types
// ----------------------------------------------------------------------
template< typename T > struct is_rvalue_reference
: public tt::primary<T, tt::_rvalue_reference > { };
// ----------------------------------------------------------------------
// is_member_object_pointer - metaprogramming type trait
// ----------------------------------------------------------------------
template< typename T > struct is_member_object_pointer
: public conditional< is_member_function_pointer<T>::value
, false_type
, tt::primary<T, tt::_member_object_pointer>
>::type
{ };
// ----------------------------------------------------------------------
// is_member_function_pointer - metaprogramming type trait
// ----------------------------------------------------------------------
template< typename T >
struct is_member_function_pointer
: public tt::primary<T, tt::_member_function_pointer > { };
// ----------------------------------------------------------------------
// is_enum - metaprogramming type trait detecting enumeration types
// ----------------------------------------------------------------------
template< typename T >
struct is_enum
: public tt::primary<T, tt::_enum > { };
// ----------------------------------------------------------------------
// is_union - metaprogramming type trait detecting union types
// ----------------------------------------------------------------------
template< typename T >
struct is_union
: public tt::primary<T, tt::_union > { };
// ----------------------------------------------------------------------
// is_class - metaprogramming type trait detecting class types
// ----------------------------------------------------------------------
template< typename T >
struct is_class
: public tt::primary<T, tt::_class > { };
// ----------------------------------------------------------------------
// is_function - metaprogramming type trait detecting function types
// ----------------------------------------------------------------------
template< typename T >
struct is_function
: public tt::primary<T, tt::_function > { };
// ----------------------------------------------------------------------
// is_reference - metaprogramming composite type trait
// ----------------------------------------------------------------------
template< typename T >
struct is_reference
: public tt::primary< T, tt::_lvalue_reference
| tt::_rvalue_reference
>
{ };
// ----------------------------------------------------------------------
// is_arithmetic - metaprogramming composite type trait
// ----------------------------------------------------------------------
template< typename T >
struct is_arithmetic
: public tt::primary< T, tt::_integral
| tt::_floating_point
>
{ };
// ----------------------------------------------------------------------
// is_fundamental - metaprogramming composite type trait
// ----------------------------------------------------------------------
template< typename T >
struct is_fundamental
: public tt::primary< T, tt::_integral
| tt::_floating_point
| tt::_void
>
{ };
// ----------------------------------------------------------------------
// is_object - metaprogramming composite type trait
// ----------------------------------------------------------------------
template< typename T >
struct is_object
: public tt::primary< T, tt::_array
| tt::_class
| tt::_enum
| tt::_floating_point
| tt::_integral
| tt::_member_object_pointer
| tt::_member_function_pointer
| tt::_pointer
| tt::_union
>
{ };
// ----------------------------------------------------------------------
// is_scalar - metaprogramming composite type trait
// ----------------------------------------------------------------------
template< typename T >
struct is_scalar
: public tt::primary< T, tt::_integral
| tt::_floating_point
| tt::_enum
| tt::_pointer
| tt::_member_object_pointer
| tt::_member_function_pointer
>
{ };
// ----------------------------------------------------------------------
// is_compound - metaprogramming composite type trait
// ----------------------------------------------------------------------
template< typename T >
struct is_compound
: public tt::primary< T, tt::_array
| tt::_pointer
| tt::_lvalue_reference
| tt::_rvalue_reference
| tt::_member_object_pointer
| tt::_member_function_pointer
| tt::_enum
| tt::_union
| tt::_class
| tt::_function
>
{ };
// ----------------------------------------------------------------------
// is_member_pointer - metaprogramming composite type trait
// ----------------------------------------------------------------------
template< typename T >
struct is_member_pointer
: public tt::primary< T, tt::_member_object_pointer
| tt::_member_function_pointer
>
{ };
// ----------------------------------------------------------------------
// cv<> - helper analyzing a type's cv-qualification(s)
// ----------------------------------------------------------------------
namespace tt {
template< typename T >
struct cv
{
static bool const is_c = false;
static bool const is_v = false;
typedef T const add_c_type;
typedef T volatile add_v_type;
typedef T const volatile add_cv_type;
typedef T rem_c_type;
typedef T rem_v_type;
typedef T rem_cv_type;
};
template< typename T >
struct cv<T const>
{
static bool const is_c = true;
static bool const is_v = false;
typedef T const add_c_type;
typedef T const volatile add_v_type;
typedef T const volatile add_cv_type;
typedef T rem_c_type;
typedef T const rem_v_type;
typedef T rem_cv_type;
};
template< typename T >
struct cv<T volatile>
{
static bool const is_c = false;
static bool const is_v = true;
typedef T const volatile add_c_type;
typedef T volatile add_v_type;
typedef T const volatile add_cv_type;
typedef T volatile rem_c_type;
typedef T rem_v_type;
typedef T rem_cv_type;
};
template< typename T >
struct cv<T const volatile>
{
static bool const is_c = true;
static bool const is_v = true;
typedef T const volatile add_c_type;
typedef T const volatile add_v_type;
typedef T const volatile add_cv_type;
typedef T volatile rem_c_type;
typedef T const rem_v_type;
typedef T rem_cv_type;
};
template< typename T >
struct cv<T &>
{
static bool const is_c = false;
static bool const is_v = false;
typedef T & add_c_type;
typedef T & add_v_type;
typedef T & add_cv_type;
typedef T & rem_c_type;
typedef T & rem_v_type;
typedef T & rem_cv_type;
};
} // namespace tt
// ----------------------------------------------------------------------
// is_const - metaprogramming type trait detecting type constness
// ----------------------------------------------------------------------
template< typename T >
struct is_const
: public integral_constant<bool, tt::cv<T>::is_c > { };
// ----------------------------------------------------------------------
// is_volatile - metaprogramming type trait detecting type volatility
// ----------------------------------------------------------------------
template< typename T >
struct is_volatile
: public integral_constant<bool, tt::cv<T>::is_v > { };
// ----------------------------------------------------------------------
// is_abstract_class - helper detecting when a class is abstract
// ----------------------------------------------------------------------
namespace tt {
template< typename, bool >
struct is_abstract_class
: public false_type { }; // default: not a class, hence not abstract
template< typename C >
struct is_abstract_class<C,true> // C is known to be a class type
{
protected:
template< typename T >
static no_t take( T (*)[1] ); // can't form array of abstract T
template< typename T >
static yes_t take( ... );
public:
static bool const value = sizeof( take<C>(0) ) == sizeof(yes_t);
}; // is_abstract_class<,true>
} // namespace tt
// ----------------------------------------------------------------------
// is_abstract - metaprogramming type trait detecting abstract classes
// ----------------------------------------------------------------------
template< typename T >
struct is_abstract
: public tt::is_abstract_class< T
, is_class<T>::value
>
{ };
// ----------------------------------------------------------------------
// is_signed - metaprogramming type trait detecting type signedness
// ----------------------------------------------------------------------
template< typename >
struct is_signed
: public false_type { };
template<>
struct is_signed<signed char>
: public true_type { };
template<>
struct is_signed<short>
: public true_type { };
template<>
struct is_signed<int>
: public true_type { };
template<>
struct is_signed<long>
: public true_type { };
template< typename T >
struct is_signed<T const>
: public is_signed<T> { };
template< typename T >
struct is_signed<T volatile>
: public is_signed<T> { };
template< typename T >
struct is_signed<T const volatile>
: public is_signed<T> { };
// ----------------------------------------------------------------------
// is_unsigned - metaprogramming type trait detecting type unsignedness
// ----------------------------------------------------------------------
template< typename >
struct is_unsigned
: public false_type { };
template<>
struct is_unsigned<unsigned char>
: public true_type { };
template<>
struct is_unsigned<unsigned short>
: public true_type { };
template<>
struct is_unsigned<unsigned int>
: public true_type { };
template<>
struct is_unsigned<unsigned long>
: public true_type { };
template< typename T >
struct is_unsigned<T const>
: public is_unsigned<T> { };
template< typename T >
struct is_unsigned<T volatile>
: public is_unsigned<T> { };
template< typename T >
struct is_unsigned<T const volatile>
: public is_unsigned<T> { };
// ----------------------------------------------------------------------
// arr<> - helper analyzing a type's array qualification(s)
// ----------------------------------------------------------------------
namespace tt {
template< typename T >
struct arr // non-array
{
typedef T rem_ext_type;
typedef T rem_arr_type;
static int const rank = 0;
template< unsigned I >
struct extent { static int const value = 0; };
};
template< typename T, unsigned N >
struct arr<T[N]>
{
typedef T rem_ext_type;
typedef typename tt::arr<T>::rem_arr_type rem_arr_type;
static int const rank = 1 + tt::arr<T>::rank;
template< unsigned I >
struct extent
{
static int const value = (I == rank)
? N
: tt::arr<T>::template extent<I>::value;
};
};
template< typename T >
struct arr<T[]>
{
typedef T rem_ext_type;
typedef T rem_arr_type;
static int const rank = 1;
template< unsigned I >
struct extent { static int const value = 0; };
};
} // namespace tt
// ----------------------------------------------------------------------
// rank - metaprogramming type trait detecting array's rank
// ----------------------------------------------------------------------
template< typename T >
struct rank
: public integral_constant<int, tt::arr<T>::rank> { };
// ----------------------------------------------------------------------
// extent - metaprogramming type trait detecting array's extent
// ----------------------------------------------------------------------
template< typename T, unsigned I >
struct extent
: public integral_constant<int, tt::arr<T>::template extent<I>::value> { };
// ----------------------------------------------------------------------
// is_same - metaprogramming type trait detecting type identity
// ----------------------------------------------------------------------
template< typename T, typename U >
struct is_same : public false_type { };
template< typename T >
struct is_same<T,T> : public true_type { };
// ----------------------------------------------------------------------
// any_conversion - helper to avoid passing a UDT through ... parameter
// ----------------------------------------------------------------------
namespace tt {
struct any_conversion
{
template< typename T >
any_conversion( T const volatile & );
template< typename T >
any_conversion( T & ); // no cv-qual on fctn-refs
}; // any_conversion
} // namespace tt
// ----------------------------------------------------------------------
// converts_to - helper detecting convertability
// ----------------------------------------------------------------------
namespace tt {
template< typename From, typename To, bool >
struct converts
: public false_type { }; // default: can't convert to abstract To
template< typename From, typename To >
struct converts<From,To,false> // To is non-abstract
{
protected:
static yes_t take( To, int );
static no_t take( any_conversion, ... );
static From from;
public:
static bool const value
= sizeof( take( from, 0 ) ) == sizeof(yes_t);
}; // converts<>
} // namespace tt
// ----------------------------------------------------------------------
// is_convertible - metaprogramming type trait detecting convertability
// ----------------------------------------------------------------------
template< typename From, typename To >
struct is_convertible
: public tt::converts<From,To,is_abstract<To>::value> { };
template< > struct is_convertible<void,void>
: public true_type { };
template< typename T >
struct is_convertible<T,void>
: public true_type { };
template< typename T >
struct is_convertible<void,T>
: public false_type { };
template< >
struct is_convertible<const void,const void>
: public true_type { };
template< typename T >
struct is_convertible<T,const void>
: public true_type { };
template< typename T >
struct is_convertible<const void,T>
: public false_type { };
template< >
struct is_convertible<volatile void,volatile void>
: public true_type { };
template< typename T >
struct is_convertible<T,volatile void>
: public true_type { };
template< typename T >
struct is_convertible<volatile void,T>
: public false_type { };
template< >
struct is_convertible<const volatile void,const volatile void>
: public true_type { };
template< typename T >
struct is_convertible<T,const volatile void>
: public true_type { };
template< typename T >
struct is_convertible<const volatile void,T>
: public false_type { };
template< typename From, int N, typename To >
struct is_convertible<From[N],To>
: public is_convertible<From*,To> { };
template< typename From, typename To, int N >
struct is_convertible<From,To[N]>
: public false_type { };
// ----------------------------------------------------------------------
// remove_const - metaprogramming type trait ensuring non-constness
// ----------------------------------------------------------------------
template< typename T >
struct remove_const
{
typedef typename tt::cv<T>::rem_c_type type;
};
// ----------------------------------------------------------------------
// remove_volatile - metaprogramming type trait ensuring non-volatility
// ----------------------------------------------------------------------
template< typename T >
struct remove_volatile
{
typedef typename tt::cv<T>::rem_v_type type;
};
// ----------------------------------------------------------------------
// remove_cv - metaprogramming type trait ensuring no cv-qualification
// ----------------------------------------------------------------------
template< typename T >
struct remove_cv
{
typedef typename tt::cv<T>::rem_cv_type type;
};
// ----------------------------------------------------------------------
// add_const - metaprogramming type trait ensuring constness
// ----------------------------------------------------------------------
template< typename T >
struct add_const
{
typedef typename tt::cv<T>::add_c_type type;
};
// ----------------------------------------------------------------------
// add_volatile - metaprogramming type trait ensuring volatility
// ----------------------------------------------------------------------
template< typename T >
struct add_volatile
{
typedef typename tt::cv<T>::add_v_type type;
};
// ----------------------------------------------------------------------
// add_cv - metaprogramming type trait ensuring constness & volatility
// ----------------------------------------------------------------------
template< typename T >
struct add_cv
{
typedef typename tt::cv<T>::add_cv_type type;
};
// ----------------------------------------------------------------------
// ref<> - helper analyzing a type's reference qualification
// ----------------------------------------------------------------------
namespace tt {
template< typename T
, primary_code = encode<T>::value
>
struct ref // non-lref && non-rref && non-void
{
typedef T& add_lref_type;
#if defined(CLHEP_HAS_RVALUE_REFERENCE)
typedef T&& add_rref_type;
#endif // CLHEP_HAS_RVALUE_REFERENCE
typedef T rem_ref_type;
};
template< typename T >
struct ref<T&,_lvalue_reference>
{
typedef T& add_lref_type;
typedef T& add_rref_type;
typedef T rem_ref_type;
};
#if defined(CLHEP_HAS_RVALUE_REFERENCE)
template< typename T >
struct ref<T&&,_rvalue_reference>
{
typedef T& add_lref_type;
typedef T&& add_rref_type;
typedef T rem_ref_type;
};
#endif // CLHEP_HAS_RVALUE_REFERENCE
template< typename T >
struct ref<T,_void>
{
typedef T add_lref_type;
typedef T add_rref_type;
typedef T rem_ref_type;
};
} // namespace tt
// ----------------------------------------------------------------------
// remove_reference - metaprogramming type trait ensuring non-reference
// ----------------------------------------------------------------------
template< typename T >
struct remove_reference
{
typedef typename tt::ref<T>::rem_ref_type type;
};
// ----------------------------------------------------------------------
// add_lvalue_reference - metaprogramming type trait ensuring lvalue-ref
// ----------------------------------------------------------------------
template< typename T >
struct add_lvalue_reference
{
typedef typename tt::ref<T>::add_lref_type type;
};
// ----------------------------------------------------------------------
// add_rvalue_reference - metaprogramming type trait ensuring rvalue-ref
// ----------------------------------------------------------------------
template< typename T >
struct add_rvalue_reference
{
typedef typename tt::ref<T>::add_rref_type type;
};
// ----------------------------------------------------------------------
// ptr<> - helper analyzing a type's pointer qualification
// ----------------------------------------------------------------------
namespace tt {
template< typename T >
struct ptr
{
typedef typename tt::ref<T>::rem_ref_type * add_ptr_type;
typedef T rem_ptr_type;
};
template< typename T >
struct ptr<T *>
{
typedef T * * add_ptr_type;
typedef T rem_ptr_type;
};
template< typename T >
struct ptr<T * const>
{
typedef T * const * add_ptr_type;
typedef T rem_ptr_type;
};
template< typename T >
struct ptr<T * volatile>
{
typedef T * volatile * add_ptr_type;
typedef T rem_ptr_type;
};
template< typename T >
struct ptr<T * const volatile>
{
typedef T * const volatile * add_ptr_type;
typedef T rem_ptr_type;
};
} // namespace tt
// ----------------------------------------------------------------------
// remove_extent - metaprogramming type trait reducing an array's extent
// ----------------------------------------------------------------------
template< typename T >
struct remove_extent
{
typedef typename tt::arr<T>::rem_ext_type type;
};
// ----------------------------------------------------------------------
// remove_all_extents - metaprogramming type trait yielding a non-array
// ----------------------------------------------------------------------
template< typename T >
struct remove_all_extents
{
typedef typename tt::arr<T>::rem_arr_type type;
};
// ----------------------------------------------------------------------
// remove_pointer - metaprogramming type trait ensuring non-pointer
// ----------------------------------------------------------------------
template< typename T >
struct remove_pointer
{
typedef typename tt::ptr<T>::rem_ptr_type type;
};
// ----------------------------------------------------------------------
// add_pointer - metaprogramming type trait ensuring pointer
// ----------------------------------------------------------------------
template< typename T >
struct add_pointer
{
typedef typename tt::ptr<T>::add_ptr_type type;
};
// ----------------------------------------------------------------------
// enable_if - metaprogramming construct for applied SFINAE
// ----------------------------------------------------------------------
template< typename T > struct enable_if<true ,T> { typedef T type; };
template< typename T > struct enable_if<false,T> { };
// ----------------------------------------------------------------------
// conditional - metaprogramming construct for type selection
// ----------------------------------------------------------------------
template< typename T, typename F > struct conditional<true ,T,F> { typedef T type; };
template< typename T, typename F > struct conditional<false,T,F> { typedef F type; };
// ----------------------------------------------------------------------
// is_ptr_convertible - variant of is_convertible, based on ptrs to types
// ----------------------------------------------------------------------
template< typename From, typename To >
struct is_ptr_convertible
{
protected:
static tt::yes_t take( To * );
static tt::no_t take( ... );
public:
static bool const value
= sizeof( take( static_cast<From*>(0) ) ) == sizeof(tt::yes_t);
}; // is_ptr_convertible<,>
// ----------------------------------------------------------------------
// enable_if_convertible - convenience metaprogramming type trait
// ----------------------------------------------------------------------
template< typename From // type of conversion's source
, typename To // type of conversion's target
, typename R // result type if conversion is valid
>
struct enable_if_convertible
: public enable_if< is_convertible<From,To>::value, R > { };
// ----------------------------------------------------------------------
// enable_if_ptr_convertible - convenience metaprogramming type trait
// ----------------------------------------------------------------------
template< typename From // type of conversion's source
, typename To // type of conversion's target
, typename R // result type if conversion is valid
>
struct enable_if_ptr_convertible
: public enable_if< is_ptr_convertible<From,To>::value, R > { };
// ----------------------------------------------------------------------
// enable_if_auto_ptr - convenience metaprogramming type trait
// ----------------------------------------------------------------------
template< typename P // pointee type
, typename R // result type
>
struct enable_if_auto_ptr { };
template< typename P, typename R >
struct enable_if_auto_ptr< std::auto_ptr<P>, R >
{
typedef R type;
};
// ----------------------------------------------------------------------
} // namespace CLHEP
#endif // CLHEP_TYPE_TRAITS_H
// ======================================================================
|