MemoryHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <memory>
8 #include <type_traits>
9 
10 namespace cpp20 {
11 namespace detail {
12 template <typename T>
13 struct unique_type {
14  using single_object = std::unique_ptr<T>;
15 };
16 
17 template <typename T>
18 struct unique_type<T[]> {
19  using array = std::unique_ptr<T[]>;
20 };
21 
22 template<typename T, size_t Bound>
23 struct unique_type<T[Bound]> { struct invalid_type { }; };
24 } // namespace detail
25 
26 template <typename T, typename... Args>
27 typename detail::unique_type<T>::single_object make_unique_for_overwrite() {
28  return std::unique_ptr<T>(new T);
29 }
30 
31 template <typename T>
32 typename detail::unique_type<T>::array make_unique_for_overwrite(
33  const size_t num) {
35 }
36 
37 template <typename T, typename... Args>
38 typename detail::unique_type<T>::invalid_type make_unique_for_overwrite(
39  Args&&...) = delete;
40 } // namespace cpp20
41 
42 /// Install a memory allocation failure handler that calls ERROR()
43 /// instead of throwing an exception.
44 void setup_memory_allocation_failure_reporting() noexcept;
cpp20
Definition: Algorithm.hpp:11
cstddef
memory
TestHelpers::VectorImpl::Bound
std::array< double, 2 > Bound
Type alias to be more expressive with distribution bounds in vector tests which call the generic math...
Definition: VectorImplTestHelper.hpp:423
std::remove_extent_t
std::unique_ptr
type_traits