From 986ffb2c7a9f0b8393b431b4856806957cacabd7 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Tue, 15 Oct 2013 15:05:49 +0400 Subject: [PATCH] Documentation regenerated --- boost/template_id.html | 2 +- boost/template_id_with_cvr.html | 2 +- boost/template_index.html | 48 ++-- ...d_rtti_on_idp5197920.html => type_id.html} | 20 +- boost/type_id_rtti_on_idp5353952.html | 54 +++++ ...6.html => type_id_rtti_on_idp5357088.html} | 10 +- boost/type_index.html | 58 ++--- boost_typeindex/examples.html | 215 +++++++++++++----- boost_typeindex/performance.html | 6 +- boost_typeindex_header_reference.html | 18 +- index.html | 12 +- standalone_HTML.manifest | 5 +- 12 files changed, 314 insertions(+), 136 deletions(-) rename boost/{type_id_rtti_on_idp5197920.html => type_id.html} (79%) create mode 100644 boost/type_id_rtti_on_idp5353952.html rename boost/{type_id_rtti_on_idp5201056.html => type_id_rtti_on_idp5357088.html} (93%) diff --git a/boost/template_id.html b/boost/template_id.html index 0e29a2d..785448e 100644 --- a/boost/template_id.html +++ b/boost/template_id.html @@ -34,7 +34,7 @@ template<typename T> template_index template_id();
-

Description

+

Description

Method for constructing template_index instance for type T. Strips const, volatile and & modifiers from T.

diff --git a/boost/template_id_with_cvr.html b/boost/template_id_with_cvr.html index c05b9dd..e4e8a24 100644 --- a/boost/template_id_with_cvr.html +++ b/boost/template_id_with_cvr.html @@ -34,7 +34,7 @@ template<typename T> template_index template_id_with_cvr();
-

Description

+

Description

Factory method for constructing template_index instance for type T. Does not strips const, volatile and & modifiers from T.

diff --git a/boost/template_index.html b/boost/template_index.html index 55cbf13..c2a3a0f 100644 --- a/boost/template_index.html +++ b/boost/template_index.html @@ -35,55 +35,59 @@ class template_index { public: // construct/copy/destruct - template_index(); + template_index(); - // public member functions - bool before(const template_index &) const; - const char * name() const; - std::string name_demangled() const; - std::size_t hash_code() const; + // public member functions + bool before(const template_index &) const; + const char * name() const; + std::string name_demangled() const; + std::size_t hash_code() const; - // public static functions - template<typename T> static template_index construct(); - template<typename T> static template_index construct_with_cvr(); + // public static functions + template<typename T> static template_index construct(); + template<typename T> static template_index construct_with_cvr(); };
-

Description

+

Description

Copyable type_info that does not require RTTI and could store const, volatile and references if constructed via construct_with_cvr()

-

+

template_index public construct/copy/destruct

  1. -
    template_index();
    Default constructor.
+
template_index();
+

Default constructor.

+
-

-template_index public member functions

+

+template_index public member functions

  1. -
    bool before(const template_index & rhs) const;
    +
    bool before(const template_index & rhs) const;

    Returns true if the type precedes the type of rhs in the collation order. The collation order is just an internal order.

  2. -
    const char * name() const;
    Returns raw name.
  3. +
    const char * name() const;
    Returns raw name.
  4. -
    std::string name_demangled() const;
    Returns user-friendly name.
  5. +
    std::string name_demangled() const;
    Returns user-friendly name.
  6. -
    std::size_t hash_code() const;
    Function for getting hash value.
  7. +
    std::size_t hash_code() const;
    +

    Function for getting hash value

    +
-

-template_index public static functions

+

+template_index public static functions

  1. -
    template<typename T> static template_index construct();
    +
    template<typename T> static template_index construct();

    Factory method for constructing template_index instance for type T. Strips const, volatile and & modifiers from T

  2. -
    template<typename T> static template_index construct_with_cvr();
    +
    template<typename T> static template_index construct_with_cvr();

    Factory method for constructing template_index instance for type T. Does not strips const, volatile and & modifiers from T

diff --git a/boost/type_id_rtti_on_idp5197920.html b/boost/type_id.html similarity index 79% rename from boost/type_id_rtti_on_idp5197920.html rename to boost/type_id.html index c727481..aef2a31 100644 --- a/boost/type_id_rtti_on_idp5197920.html +++ b/boost/type_id.html @@ -1,13 +1,13 @@ -Function template type_id_rtti_only +Function template type_id - + @@ -20,22 +20,22 @@

-PrevUpHomeNext +PrevUpHomeNext
-
+
-

Function template type_id_rtti_only

-

boost::type_id_rtti_only

+

Function template type_id

+

boost::type_id

Synopsis

// In header: <boost/type_index/type_index_impl.hpp>
 
 
-template<typename T> type_index type_id_rtti_only(T & rtti_val);
+template<typename T> type_index type_id();
-

Description

-

Function, that works exactly like C++ typeid(rtti_val) call, but returns boost::type_index. This method available only with RTTI enabled.

+

Description

+

Function, to get type_index for a type T. Strips const, volatile and & modifiers from T.

@@ -48,7 +48,7 @@

-PrevUpHomeNext +PrevUpHomeNext
diff --git a/boost/type_id_rtti_on_idp5353952.html b/boost/type_id_rtti_on_idp5353952.html new file mode 100644 index 0000000..71c805b --- /dev/null +++ b/boost/type_id_rtti_on_idp5353952.html @@ -0,0 +1,54 @@ + + + +Function template type_id_rtti_only + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+
+
+

Function template type_id_rtti_only

+

boost::type_id_rtti_only

+
+

Synopsis

+
// In header: <boost/type_index/type_index_impl.hpp>
+
+
+template<typename T> type_index type_id_rtti_only(T & rtti_val);
+
+

Description

+

Function, that works exactly like C++ typeid(rtti_val) call, but returns boost::type_index. This method available only with RTTI enabled.

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/boost/type_id_rtti_on_idp5201056.html b/boost/type_id_rtti_on_idp5357088.html similarity index 93% rename from boost/type_id_rtti_on_idp5201056.html rename to boost/type_id_rtti_on_idp5357088.html index b59e355..e2f40c4 100644 --- a/boost/type_id_rtti_on_idp5201056.html +++ b/boost/type_id_rtti_on_idp5357088.html @@ -6,7 +6,7 @@ - + @@ -20,10 +20,10 @@
-PrevUpHomeNext +PrevUpHomeNext
-
+

Function template type_id_rtti_only

boost::type_id_rtti_only

@@ -34,7 +34,7 @@ template<typename T> type_index type_id_rtti_only(T * rtti_val);
-

Description

+

Description

Function, that works exactly like C++ typeid(rtti_val) call, but returns boost::type_index. This method available only with RTTI enabled.

@@ -48,7 +48,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/boost/type_index.html b/boost/type_index.html index dc47b30..2a9a9c1 100644 --- a/boost/type_index.html +++ b/boost/type_index.html @@ -7,7 +7,7 @@ - + @@ -20,7 +20,7 @@

-PrevUpHomeNext +PrevUpHomeNext
@@ -38,64 +38,64 @@ typedef std::type_info stl_type_info; // construct/copy/destruct - type_index(); - explicit type_index(const stl_type_info &); + type_index(); + explicit type_index(const stl_type_info &); - // public member functions - bool before(type_index const &) const; - const char * name() const; - std::string name_demangled() const; - std::size_t hash_code() const; + // public member functions + bool before(type_index const &) const; + const char * name() const; + std::string name_demangled() const; + std::size_t hash_code() const; - // public static functions - template<typename T> static type_index construct(); - template<typename T> static type_index construct_rtti_only(T &); - template<typename T> static type_index construct_rtti_only(T *); + // public static functions + template<typename T> static type_index construct(); + template<typename T> static type_index construct_rtti_only(T &); + template<typename T> static type_index construct_rtti_only(T *); };
-

Description

+

Description

-

+

type_index public construct/copy/destruct

  1. -
    type_index();
    Default constructor.
  2. +
    type_index();
    Default constructor.
  3. -
    explicit type_index(const stl_type_info & inf);
    Constructs type_index from an instance of std::type_info.
  4. +
    explicit type_index(const stl_type_info & inf);
    Constructs type_index from an instance of std::type_info.
-

-type_index public member functions

+

+type_index public member functions

  1. -
    bool before(type_index const & rhs) const;
    +
    bool before(type_index const & rhs) const;

    Returns true if the type precedes the type of rhs in the collation order. The collation order is just an internal order.

  2. -
    const char * name() const;
    Returns raw name.
  3. +
    const char * name() const;
    Returns raw name.
  4. -
    std::string name_demangled() const;
    Returns user-friendly name.
  5. +
    std::string name_demangled() const;
    Returns user-friendly name.
  6. -
    std::size_t hash_code() const;
    Function for getting hash value.
  7. +
    std::size_t hash_code() const;
    Function for getting hash value.
-

-type_index public static functions

+

+type_index public static functions

  1. -
    template<typename T> static type_index construct();
    +
    template<typename T> static type_index construct();

    Factory method for constructing type_index instance for type T. Strips const, volatile and & modifiers from T.

  2. -
    template<typename T> static type_index construct_rtti_only(T & rtti_val);
    +
    template<typename T> static type_index construct_rtti_only(T & rtti_val);

    Factory function, that works exactly like C++ typeid(rtti_val) call, but returns boost::type_index. This method available only with RTTI enabled.

  3. -
    template<typename T> static type_index construct_rtti_only(T * rtti_val);
    +
    template<typename T> static type_index construct_rtti_only(T * rtti_val);

    Factory function, that works exactly like C++ typeid(rtti_val) call, but returns boost::type_index. This method available only with RTTI enabled.

@@ -112,7 +112,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/boost_typeindex/examples.html b/boost_typeindex/examples.html index 7d8e93c..d0f9264 100644 --- a/boost_typeindex/examples.html +++ b/boost_typeindex/examples.html @@ -26,82 +26,193 @@ + +
+

- All code in the examples will work with and without RTTI support. -

+ The following example shows how short (mangled) and human readable type names + could be obtained from a type. +

- Class that allows to register a given type only once.

-
class types_registry {
-    unordered_set<type_index> types_;
+
// Works with and without RTTI.
 
-public:
-    template <class T>
-    void add_type() {
-        type_index ti = type_id<T>();
-        std::cout << "Adding type " << ti << " to registry \n";
-        if (!types_.insert(ti).second)
-            throw std::logic_error("Type " + ti.name_demangled() + " already registered");
-    }
+#include <boost/type_index/type_index_minimal.hpp>
+#include <iostream>
 
-    template <class T>
-    bool has_type() const {
-        return types_.cend() != types_.find(type_id<T>());
-    }
-};
+template <class T>
+void foo(T) {
+    std::cout << "\n Short name: " << boost::type_id<T>().name();
+    std::cout << "\n Readable name: " << boost::type_id<T>().name_demangled();
+}
 
-int main () {
-    types_registry tr;
-    tr.add_type<int>();
-    tr.add_type<float>();
+struct user_defined_type{};
 
-    std::cout << "Has type int: " << tr.has_type<int>()
-        << "\nHas type std::string: " << tr.has_type<std::string>()
-        << '\n';
+int main() {
+    // Call to
+    foo(1);
+    // will output something like this:
+    //
+    // Short name: .H
+    // Readable name: int
 
-    try {
-        tr.add_type<const int>(); // Will throw
-    } catch (const std::logic_error& e) {
-        // Will print "Type int already registered"
-        std::cout << e.what() << std::endl;
-    }
+    user_defined_type t;
+    foo(t);
+    // Will output:
+    //
+    // Short name: .?AUuser_defined_type@@
+    // Readable name: struct user_defined_type
+}
+
+// The example 
+
+

+

+
+
+ +

+ The following example shows how an information about a type could be stored. + Example works with and without RTTI. +

+

+

+
#include <boost/type_index/type_index_minimal.hpp>
+#include <boost/unordered_set.hpp>
+#include <cassert>
+
+int main() {
+    boost::unordered_set<boost::type_index> types;
+
+    // Storing some `boost::type_info`s
+    types.insert(boost::type_id<int>());
+    types.insert(boost::type_id<float>());
+
+    // `types` variable contains two `boost::type_index`es:
+    assert(types.size() == 2);
+
+    // Const, volatile and reference will be striped from the type:
+    bool is_inserted = types.insert(boost::type_id<const int>()).second;
+    assert(!is_inserted);
+    assert(types.erase(boost::type_id<float&>()) == 1);
+
+    // We have erased the `float` type, only `int` remains
+    assert(*types.begin() == boost::type_id<int>());
 }
 

-

+

+
+
+ +

+ The following example shows that boost::type_index + is able to store the real type, successfully getting through all the inheritances. + Example works with RTTI only. +

- This will output:

-
Adding type int to registry
-Adding type float to registry
-Has type int: 1
-Has type std::string: 0
+
#include <boost/type_index/type_index_minimal.hpp>
+#include <iostream>
+
+struct A { virtual ~A(){} };
+struct B: public A {};
+struct C: public B {};
+
+void print_real_type(const A& a) {
+    std::cout << boost::type_id_rtti_only(a).name_demangled() << '\n';
+}
+
+int main() {
+    C c;
+    const A& c_as_a = c;
+    print_real_type(c_as_a);    // Outputs `struct C`
+    print_real_type(B());       // Outputs `struct B`
+}
 

-

+

+
+
+

- Another example, this time checking for exact parameter match. my_unary_function is a class, that stores - a function with result type ResultT - and any input parameter type. In operator(), it checks for input parameter match and - then executes the stored function: -

+ The following example shows that boost::template_index + is able to store the exact type, without stripping const, volatile and references. + Example works with and without RTTI. +

+

+ In this example we'll create a class, that stores pointer to function and + remembers the exact type of a parameter that function accepts. When an attempt + to call the stored function will be made, type of input parameter will be + checked for exact match with initail/erased type of function. +

-
template <class ResultT>
-class my_unary_function {
-    void*           function_ptr_;
-    template_index  exact_param_t_;
-    ...
+
#include <boost/type_index.hpp>
+#include <iostream>
+#include <stdexcept>
+
+class type_erased_unary_function {
+    void*                   function_ptr_;
+    boost::template_index   exact_param_t_;
+
+public:
+    template <class ParamT>
+    type_erased_unary_function(void(*ptr)(ParamT))
+        : function_ptr_(reinterpret_cast<void*>(ptr)) // ptr - is a pointer to function returning `void` and accepting parameter of type `ParamT`
+        , exact_param_t_(boost::template_id_with_cvr<ParamT>())
+    {}
 
     template <class ParamT>
-    ResultT operator()(ParamT& v) {
-        BOOST_ASSERT(exact_param_t_ == template_id_with_cvr<ParamT&>());
-        return (static_cast<ResultT(ParamT&)>(function_ptr_))(v);
+    void call(ParamT v) {
+        if (exact_param_t_ != boost::template_id_with_cvr<ParamT>()) {
+            throw std::runtime_error("Incorrect `ParamT`");
+        }
+
+        return (reinterpret_cast<void(*)(ParamT)>(function_ptr_))(v);
     }
 };
+
+void foo(int){}
+
+int main() {
+    type_erased_unary_function func(&foo);
+    func.call(100); // OK, `100` has type `int`
+
+    try {
+        int i = 100;
+
+        // An attempt to convert stored function to a function accepting reference
+        func.call<int&>(i); // Will throw, because types `int&` and `int` missmatch
+
+        assert(false);
+    } catch (const std::runtime_error& /*e*/) {}
+}
 

-

+

+
diff --git a/boost_typeindex/performance.html b/boost_typeindex/performance.html index 6e7bfe5..d4f8c9c 100644 --- a/boost_typeindex/performance.html +++ b/boost_typeindex/performance.html @@ -6,7 +6,7 @@ - + @@ -20,7 +20,7 @@

-PrevUpHomeNext +PrevUpHomeNext

@@ -58,7 +58,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/boost_typeindex_header_reference.html b/boost_typeindex_header_reference.html index 0d0ff9e..bc2ccf9 100644 --- a/boost_typeindex_header_reference.html +++ b/boost_typeindex_header_reference.html @@ -35,13 +35,13 @@

Includes all the headers of the Boost.TypeIndex library.

-

By inclusion of this file classes type_index (if RTTI is on) and template_index will be available. Consider including <boost/type_index/type_index_minimal.hpp> if you need only a type_index type with and without RTTI.

+

By inclusion of this file classes `type_index` (if RTTI is on) and `template_index` will be available. Consider including `<boost/type_index/type_index_minimal.hpp>` if you need only a type_index type with and without RTTI.

Contains implementation of template_index class.

-

Here is defined the template_index class, that is used instead of type_index class in situations when RTTI is disabled. Consider including <boost/type_index/type_index_minimal.hpp> or <boost/type_index.hpp> instead of this file.

+

Here is defined the template_index class, that is used instead of type_index class in situations when RTTI is disabled. Consider including `<boost/type_index/type_index_minimal.hpp>` or `<boost/type_index.hpp>` instead of this file.

namespace boost {
   class template_index;
   template<typename T> template_index template_id();
@@ -50,7 +50,7 @@
   // Ostream operator that will output demangled name. 
   template<typename CharT, typename TriatT> 
     std::basic_ostream< CharT, TriatT > & 
-    operator<<(std::basic_ostream< CharT, TriatT > & ostr, 
+    operator<<(std::basic_ostream< CharT, TriatT > & ostr, 
                template_index const & ind);
 
   // hash_value function overload for template_index
@@ -61,21 +61,19 @@
 
 

Contains implementation of type_index class.

-

Here is defined the type_index class, that is used in situations when RTTI is enabled. Consider including <boost/type_index/type_index_minimal.hpp> or <boost/type_index.hpp> instead of this file.

+

Here is defined the type_index class, that is used in situations when RTTI is enabled. Consider including `<boost/type_index/type_index_minimal.hpp>` or `<boost/type_index.hpp>` instead of this file.

namespace boost {
   class type_index;
-
-  // Function, to get type_index for a type T. Strips const, volatile and & modifiers from T. 
-  template<typename T> type_index type_id();
-  template<typename T> type_index type_id_rtti_only(T &);
-  template<typename T> type_index type_id_rtti_only(T *);
+  template<typename T> type_index type_id();
+  template<typename T> type_index type_id_rtti_only(T &);
+  template<typename T> type_index type_id_rtti_only(T *);
 }

This is the header that required for ussage of type_index with/without RTTI.

-

It includes only the minamally required headers and does the typedef template_index type_index; when RTTI is disabled.

+

It includes only the minamally required headers and does the `typedef template_index type_index;` when RTTI is disabled.

diff --git a/index.html b/index.html index abb1d6c..7c8ed30 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,16 @@
Motivation
Getting started
Examples
+
+
Getting + human readable and mangled type names
+
Storing + information about a type in container
+
Getting + through the inheritance to receive a real type name
+
Exact + type match: storing type with const, volatile and reference
+
Boost.TypeIndex Header Reference
Header <boost/type_index.hpp>
@@ -108,7 +118,7 @@
- +

Last revised: October 12, 2013 at 15:58:32 GMT

Last revised: October 15, 2013 at 11:01:14 GMT


diff --git a/standalone_HTML.manifest b/standalone_HTML.manifest index bc4620b..5dcdbde 100644 --- a/standalone_HTML.manifest +++ b/standalone_HTML.manifest @@ -6,7 +6,8 @@ boost/template_index.html boost/template_id.html boost/template_id_with_cvr.html boost/type_index.html -boost/type_id_rtti_on_idp5197920.html -boost/type_id_rtti_on_idp5201056.html +boost/type_id.html +boost/type_id_rtti_on_idp5353952.html +boost/type_id_rtti_on_idp5357088.html boost_typeindex/performance.html boost_typeindex/compiler_support.html