xenium
xenium
aligned_object.hpp
1
//
2
// Copyright (c) 2018-2020 Manuel Pöter.
3
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
4
//
5
6
#ifndef XENIUM_ALIGNED_OBJECT_HPP
7
#define XENIUM_ALIGNED_OBJECT_HPP
8
9
namespace
xenium {
10
24
template
<
typename
Derived, std::
size_t
Alignment = 0>
25
struct
aligned_object
{
26
static
void
*
operator
new
(
size_t
sz) {
27
return ::operator
new
(sz, alignment());
28
}
29
30
static
void
operator
delete
(
void
* p) {
31
::operator
delete
(p, alignment());
32
}
33
private
:
34
static
constexpr std::align_val_t alignment() {
35
return
static_cast<
std::align_val_t
>
(Alignment == 0 ? std::alignment_of<Derived>() : Alignment);
36
}
37
};
38
}
39
40
#endif
xenium::aligned_object
A small helper class for correctly aligned dynamic allocations of over-aligned types.
Definition:
aligned_object.hpp:25
Generated by
1.8.20