PMDK C++ bindings  1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
pmem::obj::experimental::v< T > Class Template Reference

Volatile residing on pmem class. More...

#include <libpmemobj++/experimental/v.hpp>

Public Member Functions

 v () noexcept
 Defaulted constructor.
 
 ~v ()
 Destructor.
 
voperator= (const T &rhs)
 Assignment operator.
 
voperator= (v &rhs)
 Assignment operator.
 
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y, T>::value>::type>
voperator= (v< Y > &rhs)
 Converting assignment operator from a different v<>. More...
 
template<typename... Args>
T & get (Args &&... args) noexcept
 Retrieves reference to the object. More...
 
T & unsafe_get ()
 Retrieves reference to the object. More...
 
 operator T& () noexcept
 Conversion operator back to the underlying type.
 
void swap (v &other)
 Swaps two v objects of the same type.
 

Related Functions

(Note that these are not member functions.)

template<class T >
void swap (v< T > &a, v< T > &b)
 Swaps two v objects of the same type. More...
 

Detailed Description

template<typename T>
class pmem::obj::experimental::v< T >

Volatile residing on pmem class.

v class is a property-like template class that has to be used for all volatile variables that reside on persistent memory. This class ensures that the enclosed type is always properly initialized by always calling the class default constructor exactly once per instance of the application.

This class has 8 bytes of storage overhead.

Example usage:

#include <fcntl.h>
using namespace pmem::obj;
using namespace pmem::obj::experimental;
struct foo {
foo() : counter(10){};
int counter;
};
/* pool root structure */
struct root {
v<foo> f;
};
void
v_property_example(pool<root> &pop)
{
auto proot = pop.root();
assert(proot->f.get().counter == 10);
proot->f.get().counter++;
assert(proot->f.get().counter == 11);
}
Experimental implementations.
Definition: common.hpp:130
Main libpmemobj namespace.
Definition: allocation_flag.hpp:18
Persistent smart pointer.
C++ pmemobj pool.
Volatile residing on pmem property template.

Member Function Documentation

◆ get()

template<typename T >
template<typename... Args>
T& pmem::obj::experimental::v< T >::get ( Args &&...  args)
inlinenoexcept

Retrieves reference to the object.

Parameters
[in]argsforwarded to objects constructor. If object was constructed earlier during application lifetime (even with different arguments) no constructor is called.
Returns
a reference to the object.

◆ operator=()

template<typename T >
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y, T>::value>::type>
v& pmem::obj::experimental::v< T >::operator= ( v< Y > &  rhs)
inline

Converting assignment operator from a different v<>.

Available only for convertible types.

◆ unsafe_get()

template<typename T >
T& pmem::obj::experimental::v< T >::unsafe_get ( )
inline

Retrieves reference to the object.

If object was not constructed (e.g. using get()) return value is unspecified.

Returns
a reference to the object.

Friends And Related Function Documentation

◆ swap()

template<class T >
void swap ( v< T > &  a,
v< T > &  b 
)
related

Swaps two v objects of the same type.

Non-member swap function as required by Swappable concept. en.cppreference.com/w/cpp/concept/Swappable


The documentation for this class was generated from the following file: