di 0.1.0
Loading...
Searching...
No Matches
writer.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/any/prelude.h"
4#include "di/meta/vocab.h"
8
9namespace di::io {
10namespace detail {
11 struct WriteSomeMember {
12 template<typename T>
13 constexpr auto operator()(T& writer, Span<Byte const> data) const -> Result<usize>
14 requires(requires {
15 { writer.write_some(data) } -> concepts::ImplicitlyConvertibleTo<Result<usize>>;
16 })
17 {
18 return writer.write_some(data);
19 }
20
21 template<typename T>
22 constexpr auto operator()(util::ReferenceWrapper<T> writer, Span<Byte const> data) const -> Result<usize>
23 requires(requires {
24 { (*this)(writer.get(), data) };
25 })
26 {
27 return (*this)(writer.get(), data);
28 }
29 };
30
31 struct FlushMember {
32 template<typename T>
33 constexpr auto operator()(T& writer) const -> Result<void>
34 requires(requires {
35 { writer.flush() } -> concepts::ImplicitlyConvertibleTo<Result<void>>;
36 })
37 {
38 return writer.flush();
39 }
40
41 template<typename T>
42 constexpr auto operator()(util::ReferenceWrapper<T> writer) const -> Result<void>
43 requires(requires {
44 { (*this)(writer.get()) };
45 })
46 {
47 return (*this)(writer.get());
48 }
49 };
50
51 struct InteractiveDeviceMember {
52 template<typename T>
53 constexpr auto operator()(T& writer) const -> bool
54 requires(requires {
55 { writer.interactive_device() } -> concepts::ImplicitlyConvertibleTo<bool>;
56 })
57 {
58 return writer.interactive_device();
59 }
60
61 template<typename T>
62 constexpr auto operator()(util::ReferenceWrapper<T> writer) const -> bool
63 requires(requires {
64 { (*this)(writer.get()) };
65 })
66 {
67 return (*this)(writer.get());
68 }
69 };
70
71 struct InteractiveDeviceDefault {
72 constexpr auto operator()(auto&) const -> bool { return false; }
73 };
74}
75
76struct WriteSome : Dispatcher<WriteSome, Result<usize>(This&, Span<Byte const>), detail::WriteSomeMember> {};
77struct Flush : Dispatcher<Flush, Result<void>(This&), detail::FlushMember> {};
79 : Dispatcher<InteractiveDevice, bool(This&), detail::InteractiveDeviceMember, detail::InteractiveDeviceDefault> {};
80
81constexpr inline auto write_some = WriteSome {};
82constexpr inline auto flush = Flush {};
83constexpr inline auto interactive_device = InteractiveDevice {};
84
86}
87
88namespace di::meta {
89template<typename T, concepts::Impl<io::Writer> Writer>
92}
93
94namespace di {
95using io::write_some;
96using io::Writer;
97}
detail::DispatcherImpl< Self, Sig, Tags... > Dispatcher
Definition dispatcher.h:47
Definition reader.h:7
constexpr auto flush
Definition writer.h:82
constexpr auto interactive_device
Definition writer.h:83
meta::List< WriteSome, Flush, InteractiveDevice > Writer
Definition writer.h:85
constexpr auto write_some
Definition writer.h:81
Definition merge_interfaces.h:6
meta::LikeExpected< decltype(io::write_some(util::declval< Writer & >(), util::declval< Span< Byte const > >())), T > WriterResult
Definition writer.h:90
Type< detail::LikeExpectedHelper< T, U > > LikeExpected
Definition vocab.h:60
auto declval() -> meta::AddRValueReference< T >
Definition declval.h:8
ReferenceWrapper(T &) -> ReferenceWrapper< T >
Expected< T, Error > Result
Definition result.h:8
Definition any_storable.h:9
constexpr auto data
Definition data.h:51
Definition writer.h:77
Definition writer.h:79
Definition writer.h:76
Definition core.h:5