gimo v0.1.0
Loading...
Searching...
No Matches
StdUniquePtr.hpp
Go to the documentation of this file.
1// Copyright Dominic (DNKpp) Koepke 2025.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef GIMO_EXT_STD_UNIQUE_PTR_HPP
7#define GIMO_EXT_STD_UNIQUE_PTR_HPP
8
9#pragma once
10
11#include <memory>
12
13namespace gimo
14{
15 template <typename T>
16 struct traits;
17}
18
19template <typename T, typename Deleter>
20 requires(!std::is_array_v<T>)
21struct gimo::traits<std::unique_ptr<T, Deleter>>
22{
23 static constexpr std::nullptr_t null{};
24
25 using Pointer = std::unique_ptr<T, Deleter>;
26
27 [[nodiscard]]
28 static constexpr std::add_lvalue_reference_t<T> value(Pointer const& ptr) noexcept(noexcept(*ptr))
29 {
30 return *ptr;
31 }
32
33 [[nodiscard]]
34 static constexpr std::add_rvalue_reference_t<T> value(Pointer&& ptr) noexcept(noexcept(*ptr))
35 {
36 return std::move(*ptr);
37 }
38
39 template <typename V>
40 using rebind_value = std::unique_ptr<V>;
41
42 template <typename Arg>
43 requires std::constructible_from<T, Arg&&>
44 [[nodiscard]]
45 static constexpr Pointer from_value(Arg&& arg)
46 {
47 return std::make_unique<T>(std::forward<Arg>(arg));
48 }
49};
50
51#endif
Definition AndThen.hpp:21
static constexpr std::add_rvalue_reference_t< T > value(Pointer &&ptr) noexcept(noexcept(*ptr))
Definition StdUniquePtr.hpp:34
std::unique_ptr< V > rebind_value
Definition StdUniquePtr.hpp:40
static constexpr std::nullptr_t null
Definition StdUniquePtr.hpp:23
std::unique_ptr< T, Deleter > Pointer
Definition StdUniquePtr.hpp:25
static constexpr std::add_lvalue_reference_t< T > value(Pointer const &ptr) noexcept(noexcept(*ptr))
Definition StdUniquePtr.hpp:28
static constexpr Pointer from_value(Arg &&arg)
Definition StdUniquePtr.hpp:45
The central customization point for the library.
Definition Common.hpp:102