Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
ValueProxy.hpp
Go to the documentation of this file.
1#pragma once
2#include <expected>
6
7namespace Thoth::Http::NHeaders {
8
9 template<bool IsConst, Serializable ...Ts>
10 struct ValueProxy{
11 static constexpr int Count{ sizeof...(Ts) };
12 static constexpr int Single{ sizeof...(Ts) == 1 };
13
14
15 static_assert(sizeof...(Ts) >= 1 && "At least 1 type must be provided.");
16
17 using HeaderType = std::conditional_t<IsConst, const Headers, Headers>;
18 using PatternType = std::conditional_t<Single, std::string_view, std::array<std::string_view, Count>>;
19#ifdef __cpp_pack_indexing
20 using Type = std::conditional_t<Single, Ts...[0], std::variant<Ts...>>;
21 // Lets go Microslop
22#else
23 template<class F, class...> struct First { using Type = F; };
24 using Type = std::conditional_t<Single, typename First<Ts...>::Type, std::variant<Ts...>>;
25#endif
26
28 ValueProxy(const ValueProxy&) = delete;
29
30 ValueProxy(std::string_view key, HeaderType& headers, PatternType inPattern = {});
31
32 std::optional<Type> GetAsOpt() &&;
33 std::expected<Type, HeaderErrorEnum> Get() &&;
34 std::expected<Type, InvalidHeaderFormat> GetWithDefault(Type defaultValue) &&;
35
36
37
38
39 template<class T>
40 requires (!IsConst)
41 void operator=(const T& newValue) &&; // NOLINT(*-unconventional-assign-operator)
42 template<class T>
43 requires (!IsConst)
44 void operator=(T&& newValue) &&; // NOLINT(*-unconventional-assign-operator)
45
46 template<class T>
47 requires (!IsConst)
48 void Set(const T& newValue) &&;
49 template<class T>
50 requires (!IsConst)
51 void Set(T&& newValue) &&;
52
53 template<class = void>
54 requires (!IsConst)
55 bool TrySet(std::string_view newValue) &&;
56
57 private:
58 const PatternType inPattern;
59 const std::string_view key;
60 // const PatternType outPattern;
61 HeaderType& headers;
62 };
63}
64
65#include <Thoth/Http/NHeaders/Proxy/ValueProxy.tpp>
Definition _base.hpp:5
Definition ValueProxy.hpp:23
F Type
Definition ValueProxy.hpp:23
Definition ValueProxy.hpp:10
bool TrySet(std::string_view newValue) &&
ValueProxy(const ValueProxy &)=delete
std::conditional_t< Single, typename First< Ts... >::Type, std::variant< Ts... > > Type
Definition ValueProxy.hpp:24
static constexpr int Count
Definition ValueProxy.hpp:11
std::conditional_t< IsConst, const Headers, Headers > HeaderType
Definition ValueProxy.hpp:17
std::conditional_t< Single, std::string_view, std::array< std::string_view, Count > > PatternType
Definition ValueProxy.hpp:18
void Set(const T &newValue) &&
ValueProxy(std::string_view key, HeaderType &headers, PatternType inPattern={})
std::expected< Type, HeaderErrorEnum > Get() &&
std::optional< Type > GetAsOpt() &&
std::expected< Type, InvalidHeaderFormat > GetWithDefault(Type defaultValue) &&
static constexpr int Single
Definition ValueProxy.hpp:12
ValueProxy(ValueProxy &&)=delete