29 #ifndef AURORA_PIMPL_HPP
30 #define AURORA_PIMPL_HPP
35 #include <type_traits>
68 template <
typename T, std::
size_t Size, std::
size_t Align>
76 template <
typename... Args>
80 new (storage()) T(std::forward<Args>(args)...);
88 new (storage()) T(*origin.storage());
96 new (storage()) T(std::move(*source.storage()));
103 PImpl(origin).swap(*
this);
111 PImpl(std::move(source)).swap(*
this);
126 adlSwap(*storage(), *other.storage());
163 return reinterpret_cast<T*
>(&mStorage);
166 const T* storage()
const
168 return reinterpret_cast<const T*
>(&mStorage);
173 correctSizeAndAlignWouldBe<sizeof(T), std::alignment_of<T>::value>();
176 template <std::
size_t ActualSize, std::
size_t ActualAlign>
177 void correctSizeAndAlignWouldBe()
179 static_assert(ActualSize <= Size,
"PImpl: Size too small to hold type T");
180 static_assert(ActualAlign == Align,
"PImpl: Alignment mismatch for type T");
187 typename std::aligned_storage<Size, Align>::type mStorage;
192 template <
typename T, std::
size_t Size, std::
size_t Align>
202 #endif // AURORA_PIMPL_HPP
Fast PImpl idiom.
Definition: PImpl.hpp:69
Configuration header of the library.
T * operator->()
Returns the implementation object for member access.
Definition: PImpl.hpp:145
~PImpl()
Destructor.
Definition: PImpl.hpp:117
void swap(PImpl &other)
Swaps two implementation objects.
Definition: PImpl.hpp:124
Helpers to declare and invoke swap() functions.
T & operator*()
Returns the implementation object.
Definition: PImpl.hpp:131
PImpl(PImpl &&source)
Move constructor.
Definition: PImpl.hpp:93
PImpl & operator=(const PImpl &origin)
Copy assignment operator.
Definition: PImpl.hpp:101
PImpl(Args &&...args)
Construct implementation object, forwarding arguments.
Definition: PImpl.hpp:77
PImpl(const PImpl &origin)
Copy constructor.
Definition: PImpl.hpp:85
Definition: DispatchTraits.hpp:39