1313#include < boost/rts/detail/config.hpp>
1414#include < boost/rts/detail/call_traits.hpp>
1515#include < boost/rts/detail/except.hpp>
16- #include < boost/rts/detail/type_info.hpp>
1716#include < boost/rts/detail/type_traits.hpp>
17+ #include < boost/core/typeinfo.hpp>
1818#include < boost/core/detail/static_assert.hpp>
19+ #include < cstring>
1920#include < memory>
2021#include < type_traits>
2122#include < unordered_map>
2223#include < vector>
2324
25+ #if ! defined( BOOST_NO_TYPEID )
26+ #include < typeindex>
27+ #endif
28+
2429namespace boost {
2530namespace rts {
2631
32+ namespace detail {
33+
34+ #if defined( BOOST_NO_TYPEID )
35+
36+ struct typeindex
37+ {
38+ typeindex (
39+ core::typeinfo const & ti) noexcept
40+ : n_(std::strlen(ti.name()))
41+ , ti_(&ti)
42+ {
43+ }
44+
45+ std::size_t hash_code () const noexcept
46+ {
47+ constexpr std::size_t offset_basis =
48+ (sizeof (std::size_t ) == 8 )
49+ ? 1469598103934665603ull
50+ : 2166136261u ;
51+ constexpr std::size_t prime =
52+ (sizeof (std::size_t ) == 8 )
53+ ? 1099511628211ull
54+ : 16777619u ;
55+ auto const s = ti_->name ();
56+ std::size_t h = offset_basis;
57+ for (std::size_t i = 0 ; i < n_; ++i)
58+ h = (h ^ static_cast <unsigned char >(s[i])) * prime;
59+ return h;
60+ }
61+
62+ bool operator ==(typeindex const & other) const noexcept
63+ {
64+ return n_ == other.n_ && *ti_ == *other.ti_ ;
65+ }
66+
67+ private:
68+ std::size_t n_;
69+ core::typeinfo const * ti_;
70+ };
71+
72+ } // detail
73+ } // rts
74+ } // boost
75+ namespace std {
76+ template <>
77+ struct hash < boost::rts::detail::typeindex >
78+ {
79+ std::size_t operator ()(
80+ boost::rts::detail::typeindex const & t) const noexcept
81+ {
82+ return t.hash_code ();
83+ }
84+ };
85+ } // std
86+ namespace boost {
87+ namespace rts {
88+ namespace detail {
89+
90+ #else
91+
92+ using typeindex = std::type_index;
93+
94+ #endif
95+
96+ } // detail
97+
2798/* * A container of type-erased objects
2899
29100 Objects are stored and retrieved by their type.
@@ -135,8 +206,7 @@ class polystore
135206 template <class T >
136207 T* find () const noexcept
137208 {
138- return static_cast <T*>(find (
139- detail::get_type_info<T>()));
209+ return static_cast <T*>(find (BOOST_CORE_TYPEID (T)));
140210 }
141211
142212 /* * Return a reference to the object associated with type T
@@ -457,8 +527,13 @@ class polystore
457527
458528 struct key
459529 {
460- detail::type_info const * ti;
461- void * p;
530+ detail::typeindex ti =
531+ detail::typeindex (BOOST_CORE_TYPEID(void ));
532+ void * p = nullptr ;
533+
534+ key () = default ;
535+ key (detail::typeindex const & ti_,
536+ void * p_) noexcept : ti(ti_) , p(p_) {}
462537 };
463538
464539 template <class T , class ... Key>
@@ -471,7 +546,7 @@ class polystore
471546 key kn[1 ];
472547
473548 explicit keyset (T& t) noexcept
474- : kn{{ & detail::get_type_info<T>() , &t } }
549+ : kn{ key ( detail::typeindex ( BOOST_CORE_TYPEID (T)) , &t) }
475550 {
476551 }
477552 };
@@ -484,11 +559,10 @@ class polystore
484559
485560 explicit keyset (T& t) noexcept
486561 : kn{
487- { &detail::get_type_info<T>(),
488- std::addressof (t) },
489- { &detail::get_type_info<Keys>(),
490- &static_cast <Keys&>(t) }...,
491- }
562+ key (detail::typeindex (BOOST_CORE_TYPEID (T)),
563+ std::addressof (t)),
564+ key (detail::typeindex (BOOST_CORE_TYPEID (Keys)),
565+ &static_cast <Keys&>(t))..., }
492566 {
493567 }
494568 };
@@ -509,34 +583,13 @@ class polystore
509583 void destroy () noexcept ;
510584 BOOST_RTS_DECL any& get (std::size_t i);
511585 BOOST_RTS_DECL void * find (
512- detail::type_info const & ti) const noexcept ;
586+ core::typeinfo const & ti) const noexcept ;
513587 BOOST_RTS_DECL void * insert_impl (any_ptr,
514588 key const * = nullptr , std::size_t = 0 );
515589
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-
535590 std::vector<any_ptr> v_;
536591 std::unordered_map<
537- detail::type_info const *,
538- void *, hash, eq> m_;
539-
592+ detail::typeindex, void *> m_;
540593};
541594
542595// ------------------------------------------------
0 commit comments