|
29 | 29 | \ref{support.arith.types} & Arithmetic types & \tcode{<cstdint>}, \tcode{<stdfloat>} \\ \rowsep
|
30 | 30 | \ref{support.start.term} & Start and termination & \tcode{<cstdlib>} \\ \rowsep
|
31 | 31 | \ref{support.dynamic} & Dynamic memory management & \tcode{<new>} \\ \rowsep
|
32 |
| -\ref{support.rtti} & Type identification & \tcode{<typeinfo>} \\ \rowsep |
| 32 | +\ref{support.rtti} & Type identification & \tcode{<typeinfo>}, \tcode{<typeindex>} \\ \rowsep |
33 | 33 | \ref{support.srcloc} & Source location & \tcode{<source_location>} \\ \rowsep
|
34 | 34 | \ref{support.exception} & Exception handling & \tcode{<exception>} \\ \rowsep
|
35 |
| -\ref{support.initlist} & Initializer lists & \tcode{<initializer_list>} \\ \rowsep |
| 35 | +\ref{support.initlist} & Initializer lists & \tcode{<initializer_list>} \\ \rowsep |
36 | 36 | \ref{cmp} & Comparisons & \tcode{<compare>} \\ \rowsep
|
37 | 37 | \ref{support.coroutine} & Coroutines & \tcode{<coroutine>} \\ \rowsep
|
38 | 38 | \ref{support.runtime} & Other runtime support &
|
|
3180 | 3180 | \rSec2[support.rtti.general]{General}
|
3181 | 3181 |
|
3182 | 3182 | \pnum
|
3183 |
| -The header \libheaderdef{typeinfo} defines a |
| 3183 | +The header \libheaderref{typeinfo} defines a |
3184 | 3184 | type associated with type information generated by the implementation.
|
3185 | 3185 | It also defines two types for reporting dynamic type identification errors.
|
| 3186 | +The header \libheaderrefx{typeindex}{type.index.synopsis} defines |
| 3187 | +a wrapper type for use as an index type in associative containers\iref{associative} |
| 3188 | +and in unordered associative containers\iref{unord}. |
3186 | 3189 |
|
3187 | 3190 | \rSec2[typeinfo.syn]{Header \tcode{<typeinfo>} synopsis}
|
3188 | 3191 |
|
| 3192 | +\indexheader{typeinfo}% |
3189 | 3193 | \indexlibraryglobal{type_info}%
|
3190 | 3194 | \indexlibraryglobal{bad_cast}%
|
3191 | 3195 | \indexlibraryglobal{bad_typeid}%
|
|
3365 | 3369 | An \impldef{return value of \tcode{bad_typeid::what}} \ntbs{}.
|
3366 | 3370 | \end{itemdescr}
|
3367 | 3371 |
|
| 3372 | +\rSec2[type.index.synopsis]{Header \tcode{<typeindex>} synopsis} |
| 3373 | + |
| 3374 | +\indexheader{typeindex}% |
| 3375 | +\begin{codeblock} |
| 3376 | +#include <compare> // see \ref{compare.syn} |
| 3377 | + |
| 3378 | +namespace std { |
| 3379 | + class type_index; |
| 3380 | + template<class T> struct hash; |
| 3381 | + template<> struct hash<type_index>; |
| 3382 | +} |
| 3383 | +\end{codeblock} |
| 3384 | + |
| 3385 | +\rSec2[type.index]{Class \tcode{type_index}} |
| 3386 | + |
| 3387 | +\indexlibraryglobal{type_index}% |
| 3388 | +\begin{codeblock} |
| 3389 | +namespace std { |
| 3390 | + class type_index { |
| 3391 | + public: |
| 3392 | + type_index(const type_info& rhs) noexcept; |
| 3393 | + bool operator==(const type_index& rhs) const noexcept; |
| 3394 | + bool operator< (const type_index& rhs) const noexcept; |
| 3395 | + bool operator> (const type_index& rhs) const noexcept; |
| 3396 | + bool operator<=(const type_index& rhs) const noexcept; |
| 3397 | + bool operator>=(const type_index& rhs) const noexcept; |
| 3398 | + strong_ordering operator<=>(const type_index& rhs) const noexcept; |
| 3399 | + size_t hash_code() const noexcept; |
| 3400 | + const char* name() const noexcept; |
| 3401 | + |
| 3402 | + private: |
| 3403 | + const type_info* target; // \expos |
| 3404 | + // Note that the use of a pointer here, rather than a reference, |
| 3405 | + // means that the default copy/move constructor and assignment |
| 3406 | + // operators will be provided and work as expected. |
| 3407 | + }; |
| 3408 | +} |
| 3409 | +\end{codeblock} |
| 3410 | + |
| 3411 | +\pnum |
| 3412 | +The class \tcode{type_index} provides a simple wrapper for |
| 3413 | +\tcode{type_info} which can be used as an index type in associative |
| 3414 | +containers\iref{associative} and in unordered associative |
| 3415 | +containers\iref{unord}. |
| 3416 | + |
| 3417 | +\indexlibraryctor{type_index}% |
| 3418 | +\begin{itemdecl} |
| 3419 | +type_index(const type_info& rhs) noexcept; |
| 3420 | +\end{itemdecl} |
| 3421 | + |
| 3422 | +\begin{itemdescr} |
| 3423 | +\pnum |
| 3424 | +\effects |
| 3425 | +Constructs a \tcode{type_index} object, the equivalent of \tcode{target = \&rhs}. |
| 3426 | +\end{itemdescr} |
| 3427 | + |
| 3428 | +\indexlibrarymember{operator==}{type_index}% |
| 3429 | +\begin{itemdecl} |
| 3430 | +bool operator==(const type_index& rhs) const noexcept; |
| 3431 | +\end{itemdecl} |
| 3432 | + |
| 3433 | +\begin{itemdescr} |
| 3434 | +\pnum |
| 3435 | +\returns |
| 3436 | +\tcode{*target == *rhs.target}. |
| 3437 | +\end{itemdescr} |
| 3438 | + |
| 3439 | +\indexlibrarymember{operator<}{type_index}% |
| 3440 | +\begin{itemdecl} |
| 3441 | +bool operator<(const type_index& rhs) const noexcept; |
| 3442 | +\end{itemdecl} |
| 3443 | + |
| 3444 | +\begin{itemdescr} |
| 3445 | +\pnum |
| 3446 | +\returns |
| 3447 | +\tcode{target->before(*rhs.target)}. |
| 3448 | +\end{itemdescr} |
| 3449 | + |
| 3450 | +\indexlibrarymember{operator>}{type_index}% |
| 3451 | +\begin{itemdecl} |
| 3452 | +bool operator>(const type_index& rhs) const noexcept; |
| 3453 | +\end{itemdecl} |
| 3454 | + |
| 3455 | +\begin{itemdescr} |
| 3456 | +\pnum |
| 3457 | +\returns |
| 3458 | +\tcode{rhs.target->before(*target)}. |
| 3459 | +\end{itemdescr} |
| 3460 | + |
| 3461 | +\indexlibrarymember{operator<=}{type_index}% |
| 3462 | +\begin{itemdecl} |
| 3463 | +bool operator<=(const type_index& rhs) const noexcept; |
| 3464 | +\end{itemdecl} |
| 3465 | + |
| 3466 | +\begin{itemdescr} |
| 3467 | +\pnum |
| 3468 | +\returns |
| 3469 | +\tcode{!rhs.target->before(*target)}. |
| 3470 | +\end{itemdescr} |
| 3471 | + |
| 3472 | +\indexlibrarymember{operator>=}{type_index}% |
| 3473 | +\begin{itemdecl} |
| 3474 | +bool operator>=(const type_index& rhs) const noexcept; |
| 3475 | +\end{itemdecl} |
| 3476 | + |
| 3477 | +\begin{itemdescr} |
| 3478 | +\pnum |
| 3479 | +\returns |
| 3480 | +\tcode{!target->before(*rhs.target)}. |
| 3481 | +\end{itemdescr} |
| 3482 | + |
| 3483 | +\indexlibrarymember{operator<=>}{type_index}% |
| 3484 | +\begin{itemdecl} |
| 3485 | +strong_ordering operator<=>(const type_index& rhs) const noexcept; |
| 3486 | +\end{itemdecl} |
| 3487 | + |
| 3488 | +\begin{itemdescr} |
| 3489 | +\pnum |
| 3490 | +\effects |
| 3491 | +Equivalent to: |
| 3492 | +\begin{codeblock} |
| 3493 | +if (*target == *rhs.target) return strong_ordering::equal; |
| 3494 | +if (target->before(*rhs.target)) return strong_ordering::less; |
| 3495 | +return strong_ordering::greater; |
| 3496 | +\end{codeblock} |
| 3497 | +\end{itemdescr} |
| 3498 | + |
| 3499 | +\indexlibrarymember{hash_code}{type_index}% |
| 3500 | +\begin{itemdecl} |
| 3501 | +size_t hash_code() const noexcept; |
| 3502 | +\end{itemdecl} |
| 3503 | + |
| 3504 | +\begin{itemdescr} |
| 3505 | +\pnum |
| 3506 | +\returns |
| 3507 | +\tcode{target->hash_code()}. |
| 3508 | +\end{itemdescr} |
| 3509 | + |
| 3510 | +\indexlibrarymember{name}{type_index}% |
| 3511 | +\begin{itemdecl} |
| 3512 | +const char* name() const noexcept; |
| 3513 | +\end{itemdecl} |
| 3514 | + |
| 3515 | +\begin{itemdescr} |
| 3516 | +\pnum |
| 3517 | +\returns |
| 3518 | +\tcode{target->name()}. |
| 3519 | +\end{itemdescr} |
| 3520 | + |
| 3521 | +\indexlibrarymember{hash}{type_index}% |
| 3522 | +\begin{itemdecl} |
| 3523 | +template<> struct hash<type_index>; |
| 3524 | +\end{itemdecl} |
| 3525 | + |
| 3526 | +\begin{itemdescr} |
| 3527 | +\pnum |
| 3528 | +For an object \tcode{index} of type \tcode{type_index}, |
| 3529 | +\tcode{hash<type_index>()(index)} shall evaluate to the same result as \tcode{index.hash_code()}. |
| 3530 | +\end{itemdescr} |
| 3531 | + |
3368 | 3532 | \rSec1[support.srcloc]{Source location}
|
3369 | 3533 |
|
3370 | 3534 | \rSec2[source.location.syn]{Header \tcode{<source_location>} synopsis}
|
|
0 commit comments