Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Offset may vary for different Ts
- template <typename T>
- std::ptrdiff_t list_node_payload_offset() {
- std::list<T> lst;
- lst.push_back(T{});
- auto lst_begin = lst.begin();
- return reinterpret_cast<uint8_t*>(std::addressof(lst.front())) -
- *reinterpret_cast<uint8_t**>(std::addressof(lst_begin));
- }
- #pragma GCC optimize "no-strict-aliasing"
- template <typename T>
- typename std::list<T>::iterator to_list_iterator(T& t) {
- static const auto offset = list_node_payload_offest<T>();
- auto node_address = reinterpret_cast<uint8_t*>(std::addressof(t)) - offset;
- return *reinterpret_cast<typename std::list<T>::iterator*>(&iter_value);
- }
- #pragma GCC optimize "strict-aliasing"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement