jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
jau::type_info Class Reference

Generic type information using either Runtime type information (RTTI) or Compile time type information (CTTI) More...

#include <cpp_lang_util.hpp>

Collaboration diagram for jau::type_info:

Public Member Functions

 type_info () noexcept
 Constructor for an empty type_info instance, i.e. More...
 
 type_info (const char *signature_) noexcept
 Constructor using a const char* signature with a static storage duration. More...
 
 type_info (const std::type_info &info_) noexcept
 Constructor using an RTTI std::type_info reference, i.e. More...
 
std::string demangled_name () const noexcept
 Return the demangle_name() of name(). More...
 
size_t hash_code () const noexcept
 Returns an unspecified hash code of this instance. More...
 
const char * name () const noexcept
 Returns the type name, compiler implementation specific. More...
 
bool operator!= (const type_info &rhs) const noexcept
 
constexpr bool operator== (const type_info &rhs) const noexcept
 Return true if both instances are equal. More...
 

Static Public Member Functions

static void abort_invalid (const char *signature) noexcept
 Aborts program execution if given signature is nullptr or has a string length == 0. More...
 
static constexpr bool is_valid (const char *signature) noexcept
 Returns true if given signature is not nullptr and has a string length > 0, otherwise false. More...
 

Static Public Attributes

static constexpr const bool limited_lambda_id
 Static constexpr boolean indicating whether resulting type_info uniqueness is limited for lambda function types. More...
 

Detailed Description

Generic type information using either Runtime type information (RTTI) or Compile time type information (CTTI)

jau::type_info exposes same properties as RTTI std::type_index, i.e. can be used as index in associative and unordered associative containers and is CopyConstructible and CopyAssignable.

jau::type_info is compatible with std::type_index operations.

jau::type_info can be utilized w/o RTTI using Compile time type information (CTTI) information, i.e. JAU_PRETTY_FUNCTION via jau::ctti_name<R, L, A...>().

Consider using jau::make_ctti<R, L, A...>() for construction, as it removes the RTTI and CTTI code path differences.

RTTI and Compile time type information (CTTI) Natures

If RTTI is being used, see cxx_rtti_available, jau::type_info may be instantiated with a std::type_info reference as returned from typeid(T).

Without RTTI jau::type_info may be instantiated using JAU_PRETTY_FUNCTION. Hence utilizes Compile time type information (CTTI) only.

In both cases, jau::type_info will solely operate on the const char* signature and its hash value, aligning memory footprint and operations.

Use jau::make_ctti<R, L, A...>() for construction, as it removes the RTTI and CTTI code path differences.

Notes about lifecycle and identity

Prologue

We assume block scope and static storage duration (runtime lifecycle) of

Equality Comparison

Limitations

Non unique lambda type names without RTTI using gcc or non clang compiler

Due to limitations of jau::make_ctti<R, L, A...>(), not using RTTI on gcc or non clang compiler will erroneously mistake different lambda functions defined within one function and using same function prototype R<A...> to be the same.

jau::type_info::limited_lambda_id exposes the potential limitation.

See also
Identity
jau::make_ctti<R, L, A...>
Examples
test_functional.hpp.

Definition at line 435 of file cpp_lang_util.hpp.

Constructor & Destructor Documentation

◆ type_info() [1/3]

jau::type_info::type_info ( )
inlinenoexcept

Constructor for an empty type_info instance, i.e.

empty name() signature.

Definition at line 486 of file cpp_lang_util.hpp.

◆ type_info() [2/3]

jau::type_info::type_info ( const std::type_info &  info_)
inlinenoexcept

Constructor using an RTTI std::type_info reference, i.e.

typeid(T) result.

Consider using jau::make_ctti<R, L, A...>() for construction, as it removes the RTTI and CTTI code path differences.

Parameters
info_RTTI std::type_info reference
See also
jau::make_ctti<R, L, A...>

Definition at line 500 of file cpp_lang_util.hpp.

◆ type_info() [3/3]

jau::type_info::type_info ( const char *  signature_)
inlinenoexcept

Constructor using a const char* signature with a static storage duration.

Aborts program execution if given signature is nullptr or has a string length == 0.

Parameters
signature_valid string signature of type with length > 0 with static storage duration.
See also
jau::make_ctti<R, L, A...>

Definition at line 513 of file cpp_lang_util.hpp.

Member Function Documentation

◆ is_valid()

static constexpr bool jau::type_info::is_valid ( const char *  signature)
inlinestaticconstexprnoexcept

Returns true if given signature is not nullptr and has a string length > 0, otherwise false.

Examples
test_functional.hpp.

Definition at line 468 of file cpp_lang_util.hpp.

Here is the caller graph for this function:

◆ abort_invalid()

static void jau::type_info::abort_invalid ( const char *  signature)
inlinestaticnoexcept

Aborts program execution if given signature is nullptr or has a string length == 0.

Definition at line 473 of file cpp_lang_util.hpp.

◆ operator==()

constexpr bool jau::type_info::operator== ( const type_info rhs) const
inlineconstexprnoexcept

Return true if both instances are equal.

Parameters
rhs
Returns
See also
Identity

Definition at line 524 of file cpp_lang_util.hpp.

Here is the caller graph for this function:

◆ operator!=()

bool jau::type_info::operator!= ( const type_info rhs) const
inlinenoexcept

Definition at line 535 of file cpp_lang_util.hpp.

◆ hash_code()

size_t jau::type_info::hash_code ( ) const
inlinenoexcept

Returns an unspecified hash code of this instance.

Properties

  • for all type_info objects referring to the same type, their hash code is the same.
  • type_info objects referring to different types may have the same hash code, i.e. due to hash collision.

Compatible with std::type_info definition.

Returns
Unspecified hash code of this instance.
See also
Identity

Definition at line 551 of file cpp_lang_util.hpp.

◆ name()

const char * jau::type_info::name ( ) const
inlinenoexcept

Returns the type name, compiler implementation specific.


Examples
test_functional.hpp.

Definition at line 554 of file cpp_lang_util.hpp.

Here is the caller graph for this function:

◆ demangled_name()

std::string jau::type_info::demangled_name ( ) const
inlinenoexcept

Return the demangle_name() of name().

Definition at line 558 of file cpp_lang_util.hpp.

Member Data Documentation

◆ limited_lambda_id

constexpr const bool jau::type_info::limited_lambda_id
staticconstexpr
Initial value:
=
true

Static constexpr boolean indicating whether resulting type_info uniqueness is limited for lambda function types.

Always is false if rtti_available == true, i.e. lambda function types are always unique using RTTI.

May return true if:

  • no RTTI and using gcc
  • no RTTI and not using clang
See also
CTTI lambda name limitations
Examples
test_functional.hpp, and test_functional_perf.hpp.

Definition at line 454 of file cpp_lang_util.hpp.


The documentation for this class was generated from the following file: