PMDK C++ bindings 1.13.0
This is the C++ bindings documentation for PMDK's libpmemobj.
p.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2/* Copyright 2015-2020, Intel Corporation */
3
9#ifndef LIBPMEMOBJ_CPP_P_HPP
10#define LIBPMEMOBJ_CPP_P_HPP
11
12#include <memory>
13
16
17namespace pmem
18{
19
20namespace obj
21{
34template <typename T>
35class p {
36 typedef p<T> this_type;
37
38public:
46 p(const T &_val) noexcept : val{_val}
47 {
48 }
49
53 p() = default;
54
65 p &
66 operator=(const p &rhs)
67 {
68 this_type(rhs).swap(*this);
69
70 return *this;
71 }
72
83 template <typename Y,
84 typename = typename std::enable_if<
85 std::is_convertible<Y, T>::value>::type>
86 p &
87 operator=(const p<Y> &rhs)
88 {
89 this_type(rhs).swap(*this);
90
91 return *this;
92 }
93
97 operator T() const noexcept
98 {
99 return this->val;
100 }
101
112 T &
114 {
115 detail::conditional_add_to_tx(this);
116
117 return this->val;
118 }
119
127 const T &
128 get_ro() const noexcept
129 {
130 return this->val;
131 }
132
139 void
140 swap(p &other)
141 {
142 detail::conditional_add_to_tx(this);
143 detail::conditional_add_to_tx(&other);
144 std::swap(this->val, other.val);
145 }
146
147private:
148 T val;
149};
150
157template <class T>
158inline void
160{
161 a.swap(b);
162}
163
164} /* namespace obj */
165
166} /* namespace pmem */
167
168#endif /* LIBPMEMOBJ_CPP_P_HPP */
Resides on pmem class.
Definition: p.hpp:35
p(const T &_val) noexcept
Value constructor.
Definition: p.hpp:46
T & get_rw()
Retrieves read-write reference of the object.
Definition: p.hpp:113
void swap(p &other)
Swaps two p objects of the same type.
Definition: p.hpp:140
p()=default
Defaulted constructor.
p & operator=(const p &rhs)
Assignment operator.
Definition: p.hpp:66
const T & get_ro() const noexcept
Retrieves read-only const reference of the object.
Definition: p.hpp:128
p & operator=(const p< Y > &rhs)
Converting assignment operator from a different p<>.
Definition: p.hpp:87
Commonly used functionality.
void swap(p< T > &a, p< T > &b)
Swaps two p objects of the same type.
Definition: p.hpp:159
void swap(pmem::obj::array< T, N > &lhs, pmem::obj::array< T, N > &rhs)
Non-member swap function.
Definition: array.hpp:909
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Helper template for persistent ptr specialization.