any_ref.cpp 670 Bytes
Newer Older
1
#include <py/core/any_ref.hpp>
2
#include <py/core/any_ref_placeholder.hpp>
3

4
#include <any>
5

6
7
namespace mln::py
{
8
9
10
11
12
13
14
15
16
  struct cast_dispatcher_t
  {
    template <typename U> // U return type
    void call(void* held, std::byte* ptr)
    {
      new (held) placeholder<U>(reinterpret_cast<U*>(ptr));
    }
  };

17

18
19
20
21
22
  any_ref::any_ref(std::byte* ptr, Info i)
  {
    visit_f(i.tid(), cast_dispatcher_t(), reinterpret_cast<void*>(&m_held), ptr);
  }

23
24
25
  void* any_ref::data() { return reinterpret_cast<placeholder_base*>(&m_held)->m_data; }

  const std::type_info& any_ref::type() const { return reinterpret_cast<const placeholder_base*>(&m_held)->type(); }
26
} // namespace mln::py