tlx
Toggle main menu visibility
Loading...
Searching...
No Matches
allocator_base.hpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* tlx/allocator_base.hpp
3
*
4
* Part of tlx - http://panthema.net/tlx
5
*
6
* Copyright (C) 2015 Timo Bingmann <tb@panthema.net>
7
*
8
* All rights reserved. Published under the Boost Software License, Version 1.0
9
******************************************************************************/
10
11
#ifndef TLX_ALLOCATOR_BASE_HEADER
12
#define TLX_ALLOCATOR_BASE_HEADER
13
14
#include <cstddef>
15
#include <memory>
16
#include <type_traits>
17
18
namespace
tlx
{
19
20
template
<
typename
Type>
21
class
AllocatorBase
22
{
23
static
constexpr
bool
debug
=
true
;
24
25
public
:
26
using
value_type
= Type;
27
using
pointer
= Type*;
28
using
const_pointer
=
const
Type*;
29
using
reference
= Type&;
30
using
const_reference
=
const
Type&;
31
using
size_type
= std::size_t;
32
using
difference_type
= std::ptrdiff_t;
33
34
//! C++11 type flag
35
using
is_always_equal
= std::true_type;
36
//! C++11 type flag
37
using
propagate_on_container_move_assignment
= std::true_type;
38
39
//! Returns the address of x.
40
pointer
address
(
reference
x)
const
noexcept
{
41
return
std::addressof(x);
42
}
43
44
//! Returns the address of x.
45
const_pointer
address
(
const_reference
x)
const
noexcept
{
46
return
std::addressof(x);
47
}
48
49
//! Maximum size possible to allocate
50
size_type
max_size
() const noexcept {
51
return
size_t(-1) /
sizeof
(Type);
52
}
53
54
#if __cplusplus >= 201103L
55
//! Constructs an element object on the location pointed by p.
56
template
<
typename
SubType,
typename
... Args>
57
void
construct
(SubType* p, Args&& ... args)
58
noexcept
(std::is_nothrow_constructible<SubType, Args...>::value) {
59
::new (
static_cast<
void
*
>
(p))SubType(std::forward<Args>(args) ...);
// NOLINT
60
}
61
62
//! Destroys in-place the object pointed by p.
63
template
<
typename
SubType>
64
void
destroy
(SubType* p)
const
noexcept
(std::is_nothrow_destructible<SubType>::value) {
65
p->~SubType();
66
}
67
#else
68
//! Constructs an element object on the location pointed by p.
69
void
construct
(
pointer
p,
const_reference
value) {
70
::new (
static_cast<
void
*
>
(p))Type(value);
// NOLINT
71
}
72
73
#if defined(_MSC_VER)
74
// disable false-positive warning C4100: 'p': unreferenced formal parameter
75
#pragma warning(push)
76
#pragma warning(disable:4100)
77
#endif
78
//! Destroys in-place the object pointed by p.
79
void
destroy
(
pointer
p)
const
noexcept
{
80
p->~Type();
81
}
82
#if defined(_MSC_VER)
83
#pragma warning(push)
84
#endif
85
#endif
86
};
87
88
}
// namespace tlx
89
90
#endif
// !TLX_ALLOCATOR_BASE_HEADER
91
92
/******************************************************************************/
tlx::AllocatorBase
Definition
allocator_base.hpp:22
tlx::AllocatorBase::reference
Type & reference
Definition
allocator_base.hpp:29
tlx::AllocatorBase::propagate_on_container_move_assignment
std::true_type propagate_on_container_move_assignment
C++11 type flag.
Definition
allocator_base.hpp:37
tlx::AllocatorBase::destroy
void destroy(pointer p) const noexcept
Destroys in-place the object pointed by p.
Definition
allocator_base.hpp:79
tlx::AllocatorBase::is_always_equal
std::true_type is_always_equal
C++11 type flag.
Definition
allocator_base.hpp:35
tlx::AllocatorBase::pointer
Type * pointer
Definition
allocator_base.hpp:27
tlx::AllocatorBase::debug
static constexpr bool debug
Definition
allocator_base.hpp:23
tlx::AllocatorBase::address
const_pointer address(const_reference x) const noexcept
Returns the address of x.
Definition
allocator_base.hpp:45
tlx::AllocatorBase::const_reference
const Type & const_reference
Definition
allocator_base.hpp:30
tlx::AllocatorBase::max_size
size_type max_size() const noexcept
Maximum size possible to allocate.
Definition
allocator_base.hpp:50
tlx::AllocatorBase::address
pointer address(reference x) const noexcept
Returns the address of x.
Definition
allocator_base.hpp:40
tlx::AllocatorBase::construct
void construct(pointer p, const_reference value)
Constructs an element object on the location pointed by p.
Definition
allocator_base.hpp:69
tlx::AllocatorBase::difference_type
std::ptrdiff_t difference_type
Definition
allocator_base.hpp:32
tlx::AllocatorBase::value_type
Type value_type
Definition
allocator_base.hpp:26
tlx::AllocatorBase::size_type
std::size_t size_type
Definition
allocator_base.hpp:31
tlx::AllocatorBase::const_pointer
const Type * const_pointer
Definition
allocator_base.hpp:28
tlx
Definition
exclusive_scan.hpp:17
tlx
allocator_base.hpp
Generated on
for tlx by
1.17.0