RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
DefaultInitAllocatorAdaptor.h
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2018 Roman Lebedev
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#pragma once
22
23#include <cstddef>
24#include <memory>
25#include <type_traits>
26
27namespace rawspeed {
28
29template <typename T, typename ActualAllocator = std::allocator<T>>
31public:
32 using allocator_traits = std::allocator_traits<ActualAllocator>;
33
34 using value_type = typename allocator_traits::value_type;
35
36 static_assert(std::is_same_v<T, value_type>);
37
38 template <class To> struct rebind final {
40 To, typename allocator_traits::template rebind_alloc<To>>;
41 };
42
44 typename allocator_traits::template rebind_alloc<value_type>;
45
47
48 [[nodiscard]] const allocator_type& get_allocator() const noexcept {
49 return allocator;
50 }
51
52 DefaultInitAllocatorAdaptor() noexcept = default;
53
55 const allocator_type& allocator_) noexcept
56 : allocator(allocator_) {}
57
58 template <class To>
61 To, typename allocator_traits::template rebind_alloc<To>>&
62 allocator_) noexcept
63 : allocator(allocator_.get_allocator()) {}
64
65 T* allocate(std::size_t n) {
66 return allocator_traits::allocate(allocator, n);
67 }
68
69 void deallocate(T* p, std::size_t n) noexcept {
70 allocator_traits::deallocate(allocator, p, n);
71 }
72
73 template <typename U>
74 void construct(U* ptr) const
75 noexcept(std::is_nothrow_default_constructible_v<U>) {
76 ::new (static_cast<void*>(ptr)) U; // start the life-time, but do not init.
77 }
78
80 typename allocator_traits::propagate_on_container_copy_assignment;
82 typename allocator_traits::propagate_on_container_move_assignment;
84 typename allocator_traits::propagate_on_container_swap;
85};
86
87template <typename T0, typename A0, typename T1, typename A1>
89 DefaultInitAllocatorAdaptor<T1, A1> const& y) noexcept {
90 return x.get_allocator() == y.get_allocator();
91}
92
93template <typename T0, typename A0, typename T1, typename A1>
95 DefaultInitAllocatorAdaptor<T1, A1> const& y) noexcept {
96 return !(x == y);
97}
98
99} // namespace rawspeed
dim y
Definition Common.cpp:51
dim x
Definition Common.cpp:50
void construct(U *ptr) const noexcept(std::is_nothrow_default_constructible_v< U >)
void deallocate(T *p, std::size_t n) noexcept
DefaultInitAllocatorAdaptor(const DefaultInitAllocatorAdaptor< To, typename allocator_traits::template rebind_alloc< To > > &allocator_) noexcept
const allocator_type & get_allocator() const noexcept
std::allocator_traits< ActualAllocator > allocator_traits
typename allocator_traits::propagate_on_container_move_assignment propagate_on_container_move_assignment
typename allocator_traits::propagate_on_container_copy_assignment propagate_on_container_copy_assignment
DefaultInitAllocatorAdaptor() noexcept=default
typename allocator_traits::value_type value_type
bool operator!=(const AlignedAllocator< T1, A1 > &, const AlignedAllocator< T2, A2 > &)
throw T(buf.data())
bool operator==(const AlignedAllocator< T1, A1 > &, const AlignedAllocator< T2, A2 > &)
DefaultInitAllocatorAdaptor< To, typename allocator_traits::template rebind_alloc< To > > other