Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 4745d68

Browse files
igchorJanDorniak99
authored andcommitted
Add void specialization for self_relative_ptr
1 parent 485353b commit 4745d68

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

include/libpmemobj++/experimental/self_relative_ptr.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,43 @@ namespace obj
2121
namespace experimental
2222
{
2323

24+
template <typename T>
25+
class self_relative_ptr;
26+
27+
template <>
28+
class self_relative_ptr<void> : public self_relative_ptr_base {
29+
public:
30+
using base_type = self_relative_ptr_base;
31+
using this_type = self_relative_ptr;
32+
using element_type = void;
33+
34+
constexpr self_relative_ptr() noexcept = default;
35+
36+
constexpr self_relative_ptr(std::nullptr_t) noexcept
37+
: self_relative_ptr_base()
38+
{
39+
}
40+
41+
self_relative_ptr(element_type *ptr) noexcept
42+
: self_relative_ptr_base(self_offset(ptr))
43+
{
44+
}
45+
46+
inline element_type *
47+
get() const noexcept
48+
{
49+
return static_cast<element_type *>(
50+
self_relative_ptr_base::to_void_pointer());
51+
}
52+
53+
private:
54+
difference_type
55+
self_offset(element_type *ptr) const noexcept
56+
{
57+
return base_type::pointer_to_offset(static_cast<void *>(ptr));
58+
}
59+
};
60+
2461
/**
2562
* Persistent self-relative pointer class.
2663
*

0 commit comments

Comments
 (0)