1010#ifndef BOOST_RTS_POLYSTORE_HPP
1111#define BOOST_RTS_POLYSTORE_HPP
1212
13+ #define BOOST_NO_TYPEID
14+
1315#include < boost/rts/detail/config.hpp>
1416#include < boost/rts/detail/call_traits.hpp>
1517#include < boost/rts/detail/except.hpp>
16- #include < boost/rts/detail/type_info.hpp>
1718#include < boost/rts/detail/type_traits.hpp>
19+ #include < boost/core/typeinfo.hpp>
1820#include < boost/core/detail/static_assert.hpp>
21+ #include < cstring>
1922#include < memory>
2023#include < type_traits>
2124#include < unordered_map>
2225#include < vector>
2326
27+ #if ! defined( BOOST_NO_TYPEID )
28+ #include < typeindex>
29+ #endif
30+
2431namespace boost {
2532namespace rts {
2633
34+ namespace detail {
35+
36+ #if defined( BOOST_NO_TYPEID )
37+
38+ struct typeindex
39+ {
40+ typeindex (
41+ core::typeinfo const & ti) noexcept
42+ : n_(std::strlen(ti.name()))
43+ , ti_(&ti)
44+ {
45+ }
46+
47+ std::size_t hash_code () const noexcept
48+ {
49+ constexpr std::size_t offset_basis =
50+ (sizeof (std::size_t ) == 8 )
51+ ? 1469598103934665603ull
52+ : 2166136261u ;
53+ constexpr std::size_t prime =
54+ (sizeof (std::size_t ) == 8 )
55+ ? 1099511628211ull
56+ : 16777619u ;
57+ auto const s = ti_->name ();
58+ std::size_t h = offset_basis;
59+ for (std::size_t i = 0 ; i < n_; ++i)
60+ h = (h ^ static_cast <unsigned char >(s[i])) * prime;
61+ return h;
62+ }
63+
64+ bool operator ==(typeindex const & other) const noexcept
65+ {
66+ return n_ == other.n_ && *ti_ == *other.ti_ ;
67+ }
68+
69+ private:
70+ std::size_t n_;
71+ core::typeinfo const * ti_;
72+ };
73+
74+ } // detail
75+ } // rts
76+ } // boost
77+ namespace std {
78+ template <>
79+ struct hash < boost::rts::detail::typeindex >
80+ {
81+ std::size_t operator ()(
82+ boost::rts::detail::typeindex const & t) const noexcept
83+ {
84+ return t.hash_code ();
85+ }
86+ };
87+ } // std
88+ namespace boost {
89+ namespace rts {
90+ namespace detail {
91+
92+ #else
93+
94+ using typeindex = std::type_index;
95+
96+ #endif
97+
98+ } // detail
99+
27100/* * A container of type-erased objects
28101
29102 Objects are stored and retrieved by their type.
@@ -135,8 +208,7 @@ class polystore
135208 template <class T >
136209 T* find () const noexcept
137210 {
138- return static_cast <T*>(find (
139- detail::get_type_info<T>()));
211+ return static_cast <T*>(find (BOOST_CORE_TYPEID (T)));
140212 }
141213
142214 /* * Return a reference to the object associated with type T
@@ -457,8 +529,8 @@ class polystore
457529
458530 struct key
459531 {
460- detail::type_info const * ti ;
461- void * p;
532+ detail::typeindex ti; // = BOOST_CORE_TYPEID(void) ;
533+ void * p;// = nullptr;
462534 };
463535
464536 template <class T , class ... Key>
@@ -471,7 +543,7 @@ class polystore
471543 key kn[1 ];
472544
473545 explicit keyset (T& t) noexcept
474- : kn{{ & detail::get_type_info<T>( ), &t }}
546+ : kn{{ detail::typeindex ( BOOST_CORE_TYPEID (T) ), &t }}
475547 {
476548 }
477549 };
@@ -484,9 +556,9 @@ class polystore
484556
485557 explicit keyset (T& t) noexcept
486558 : kn{
487- { & detail::get_type_info<T>( ),
559+ { detail::typeindex ( BOOST_CORE_TYPEID (T) ),
488560 std::addressof (t) },
489- { & detail::get_type_info<Keys>( ),
561+ { detail::typeindex ( BOOST_CORE_TYPEID (Keys) ),
490562 &static_cast <Keys&>(t) }...,
491563 }
492564 {
@@ -509,34 +581,13 @@ class polystore
509581 void destroy () noexcept ;
510582 BOOST_RTS_DECL any& get (std::size_t i);
511583 BOOST_RTS_DECL void * find (
512- detail::type_info const & ti) const noexcept ;
584+ core::typeinfo const & ti) const noexcept ;
513585 BOOST_RTS_DECL void * insert_impl (any_ptr,
514586 key const * = nullptr , std::size_t = 0 );
515587
516- struct hash
517- {
518- std::size_t operator ()(
519- detail::type_info const * p) const noexcept
520- {
521- return p->hash_code ();
522- }
523- };
524-
525- struct eq
526- {
527- bool operator ()(
528- detail::type_info const * p0,
529- detail::type_info const * p1) const noexcept
530- {
531- return *p0 == *p1;
532- }
533- };
534-
535588 std::vector<any_ptr> v_;
536589 std::unordered_map<
537- detail::type_info const *,
538- void *, hash, eq> m_;
539-
590+ detail::typeindex, void *> m_;
540591};
541592
542593// ------------------------------------------------
0 commit comments