di 0.1.0
Loading...
Searching...
No Matches
to_owned.h
Go to the documentation of this file.
1#pragma once
2
5#include "di/meta/util.h"
6#include "di/util/create.h"
7
8namespace di::util {
9namespace detail {
10 template<typename T>
11 concept MemberToOwned = requires(T&& value) { util::forward<T>(value).to_owned(); };
12
13 struct ToOwnedFunction : function::pipeline::EnablePipeline {
14 template<typename T>
15 requires(concepts::TagInvocable<ToOwnedFunction, T> || MemberToOwned<T>)
16 constexpr auto operator()(T&& value) const {
17 if constexpr (concepts::TagInvocable<ToOwnedFunction, T>) {
18 return function::tag_invoke(*this, util::forward<T>(value));
19 } else {
20 return util::forward<T>(value).to_owned();
21 }
22 }
23 };
24}
25
26constexpr inline auto to_owned = detail::ToOwnedFunction {};
27
28template<typename Self, typename T>
29struct OwnedType {
30public:
31 constexpr auto to_owned() const { return util::to_owned(static_cast<Self const&>(*this)); }
32
33private:
34 template<concepts::RemoveCVRefSameAs<Self> This>
35 constexpr friend auto tag_invoke(types::Tag<util::to_owned>, This&& self) {
36 return util::create<T>(util::forward<This>(self));
37 }
38};
39}
40
41namespace di {
42using util::to_owned;
43}
constexpr tag_invoke_detail::TagInvokeFn tag_invoke
Definition tag_invoke.h:22
constexpr auto value
Definition value.h:34
di::meta::Decay< decltype(T)> Tag
Definition tag_invoke.h:28
Definition vocab.h:96
constexpr auto to_owned
Definition to_owned.h:26
constexpr auto create(Args &&... args)
Definition create.h:21
Definition any_storable.h:9
Definition this.h:4
Definition to_owned.h:29
constexpr auto to_owned() const
Definition to_owned.h:31
constexpr friend auto tag_invoke(types::Tag< util::to_owned >, This &&self)
Definition to_owned.h:35