| 1 | /* Copyright 2023 Christian Mazakas. |
| 2 | * Distributed under the Boost Software License, Version 1.0. |
| 3 | * (See accompanying file LICENSE_1_0.txt or copy at |
| 4 | * http://www.boost.org/LICENSE_1_0.txt) |
| 5 | * |
| 6 | * See https://www.boost.org/libs/unordered for library home page. |
| 7 | */ |
| 8 | |
| 9 | #ifndef BOOST_UNORDERED_DETAIL_FOA_ELEMENT_TYPE_HPP |
| 10 | #define BOOST_UNORDERED_DETAIL_FOA_ELEMENT_TYPE_HPP |
| 11 | |
| 12 | #include <boost/core/pointer_traits.hpp> |
| 13 | |
| 14 | namespace boost{ |
| 15 | namespace unordered{ |
| 16 | namespace detail{ |
| 17 | namespace foa{ |
| 18 | |
| 19 | template<class T,class VoidPtr> |
| 20 | struct element_type |
| 21 | { |
| 22 | using value_type=T; |
| 23 | using pointer=typename boost::pointer_traits<VoidPtr>::template rebind<T>; |
| 24 | |
| 25 | pointer p; |
| 26 | |
| 27 | /* |
| 28 | * we use a deleted copy constructor here so the type is no longer |
| 29 | * trivially copy-constructible which inhibits our memcpy |
| 30 | * optimizations when copying the tables |
| 31 | */ |
| 32 | element_type()=default; |
| 33 | element_type(pointer p_):p(p_){} |
| 34 | element_type(element_type const&)=delete; |
| 35 | element_type(element_type&& rhs)noexcept |
| 36 | { |
| 37 | p = rhs.p; |
| 38 | rhs.p = nullptr; |
| 39 | } |
| 40 | |
| 41 | element_type& operator=(element_type const&)=delete; |
| 42 | element_type& operator=(element_type&& rhs)noexcept |
| 43 | { |
| 44 | if (this!=&rhs){ |
| 45 | p=rhs.p; |
| 46 | rhs.p=nullptr; |
| 47 | } |
| 48 | return *this; |
| 49 | } |
| 50 | |
| 51 | void swap(element_type& rhs)noexcept |
| 52 | { |
| 53 | auto tmp=p; |
| 54 | p=rhs.p; |
| 55 | rhs.p=tmp; |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | #endif // BOOST_UNORDERED_DETAIL_FOA_ELEMENT_TYPE_HPP |
| 65 | |