Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class stl_type_index

boost::typeindex::stl_type_index

Synopsis

// In header: <boost/type_index/stl_type_index.hpp>


class stl_type_index : public boost::typeindex::type_index_facade< stl_type_index, std::type_info >
{
public:
  // types
  typedef std::type_info type_info_t;

  // construct/copy/destruct
  stl_type_index() noexcept;
  stl_type_index(const type_info_t &) noexcept;

  // public member functions
  const type_info_t & type_info() const noexcept;
  const char * raw_name() const noexcept;
  const char * name() const noexcept;
  std::string pretty_name() const;
  std::size_t hash_code() const noexcept;
  bool equal(const stl_type_index &) const noexcept;
  bool before(const stl_type_index &) const noexcept;

  // public static functions
  template<typename T> static stl_type_index type_id() noexcept;
  template<typename T> static stl_type_index type_id_with_cvr() noexcept;
  template<typename T> 
    static stl_type_index type_id_runtime(const T &) noexcept;
};

Description

This class is a wrapper around std::type_info, that workarounds issues and provides much more rich interface. For description of functions see type_index_facade.

This class requires typeid() to work. For cases when RTTI is disabled see ctti_type_index.

stl_type_index public construct/copy/destruct

  1. stl_type_index() noexcept;
  2. stl_type_index(const type_info_t & data) noexcept;

stl_type_index public member functions

  1. const type_info_t & type_info() const noexcept;

    Override: This function may be redefined in Derived class. Overrides must not throw.

    Returns:

    Const reference to underlying low level type_info_t.

  2. const char * raw_name() const noexcept;

    Override: This function must be redefined in Derived class. Overrides must not throw.

    Returns:

    Pointer to unredable/raw type name.

  3. const char * name() const noexcept;

    Override: This function may be redefined in Derived class. Overrides must not throw.

    Returns:

    Name of a type. By default returns Derived::raw_name().

  4. std::string pretty_name() const;

    Override: This function may be redefined in Derived class. Overrides may throw.

    Returns:

    Human readable type name. By default returns Derived::name().

  5. std::size_t hash_code() const noexcept;

    Override: This function may be redefined in Derived class. Overrides must not throw.

    [Note] Note

    <boost/functional/hash.hpp> has to be included if this function is used.

    Returns:

    Hash code of a type. By default hashes types by raw_name().

  6. bool equal(const stl_type_index & rhs) const noexcept;

    Override: This function may be redefined in Derived class. Overrides must not throw.

    Returns:

    True if two types are equal. By default compares types by raw_name().

  7. bool before(const stl_type_index & rhs) const noexcept;

    Override: This function may be redefined in Derived class. Overrides must not throw.

    Returns:

    True if rhs is greater than this. By default compares types by raw_name().

stl_type_index public static functions

  1. template<typename T> static stl_type_index type_id() noexcept;

    This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id() will call this method, if Derived has same type as boost::typeindex::type_index.

    Override: This function may be redefined and made public in Derived class. Overrides must not throw. Overrides must remove const, volatile && and & modifiers from T.

    Template Parameters:

    T

    Type for which type_index must be created.

    Returns:

    type_index for type T.

  2. template<typename T> static stl_type_index type_id_with_cvr() noexcept;

    This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id_with_cvr() will call this method, if Derived has same type as boost::typeindex::type_index.

    Override: This function may be redefined and made public in Derived class. Overrides must not throw. Overrides must not remove const, volatile && and & modifiers from T.

    Template Parameters:

    T

    Type for which type_index must be created.

    Returns:

    type_index for type T.

  3. template<typename T> 
      static stl_type_index type_id_runtime(const T & variable) noexcept;

    This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id_runtime(const T&) will call this method, if Derived has same type as boost::typeindex::type_index.

    Override: This function may be redefined and made public in Derived class.

    Parameters:

    variable

    Variable which runtime type will be stored in type_index.

    Returns:

    type_index with runtime type of variable.


PrevUpHomeNext