Sequoia
Loading...
Searching...
No Matches
Handlers.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2018. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
18
19#include <memory>
20
21namespace sequoia::object
22{
23 template<class T>
25 {
26 template<class... Args>
27 requires initializable_from<T, Args...>
28 [[nodiscard]]
29 std::shared_ptr<T> operator()(Args&&... args) const
30 {
31 return std::shared_ptr<T>(new T{std::forward<Args>(args)...});
32 }
33 };
34
35 template<class T>
36 struct shared
37 {
38 public:
39 using product_type = std::shared_ptr<T>;
40 using value_type = T;
42
43 [[nodiscard]]
44 static T& get(product_type& ptr) noexcept
45 {
46 return *ptr;
47 }
48
49 [[nodiscard]]
50 static const T& get(const product_type& ptr) noexcept
51 {
52 return *ptr;
53 }
54
55 [[nodiscard]]
56 static T* get_ptr(product_type& ptr) noexcept
57 {
58 return ptr.get();
59 }
60
61 [[nodiscard]]
62 static const T* get_ptr(const product_type& ptr) noexcept
63 {
64 return ptr.get();
65 }
66 };
67
68 template<class T>
69 struct by_value
70 {
71 public:
72 using product_type = T;
73 using value_type = T;
75
76 [[nodiscard]]
77 constexpr static T& get(T& in) noexcept { return in; }
78
79 [[nodiscard]]
80 constexpr static const T& get(const T& in) noexcept { return in; }
81
82 [[nodiscard]]
83 constexpr static T* get_ptr(T& in) noexcept { return &in; }
84
85 [[nodiscard]]
86 constexpr static const T* get_ptr(const T& in) noexcept { return &in; }
87 };
88}
Traits, Concepts and basic utilities for the creation of objects.
Traits and Concepts for Sharing Policies.
Creates a product for T.
Definition: Creator.hpp:74
A concept similar to std::constructible_from, but which considers braced-init.
Definition: Concepts.hpp:75
Definition: Handlers.hpp:70
Definition: Handlers.hpp:25
Definition: Handlers.hpp:37