HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
forward_value.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#include <type_traits>
6#include <string>
7#include <string_view>
8
9#pragma once
10
11namespace hi::inline v1 {
12
28template<typename T>
30 using type = std::remove_cvref_t<T>;
31
32 [[nodiscard]] type operator()(T const &t) const noexcept
33 {
34 return t;
35 }
36};
37
38#define MAKE_FORWARD_VALUE(TEMPLATE_TYPE, RETURN_TYPE, ARGUMENT_TYPE) \
39 template<> \
40 struct forward_value<TEMPLATE_TYPE> { \
41 using type = RETURN_TYPE; \
42\
43 [[nodiscard]] type operator()(ARGUMENT_TYPE t) const noexcept \
44 { \
45 return type{t}; \
46 } \
47 };
48
49// Copy string_view by string value.
50MAKE_FORWARD_VALUE(std::string_view, std::string, std::string_view const &)
51MAKE_FORWARD_VALUE(std::string_view const, std::string, std::string_view const &)
52MAKE_FORWARD_VALUE(std::string_view &, std::string, std::string_view const &)
53MAKE_FORWARD_VALUE(std::string_view const &, std::string, std::string_view const &)
54
55// Copy char pointers by string value.
56MAKE_FORWARD_VALUE(char *, std::string, char const *)
57MAKE_FORWARD_VALUE(char const *, std::string, char const *)
58MAKE_FORWARD_VALUE(char *const, std::string, char const *)
59MAKE_FORWARD_VALUE(char const *const, std::string, char const *)
60MAKE_FORWARD_VALUE(char *&, std::string, char const *)
61MAKE_FORWARD_VALUE(char const *&, std::string, char const *)
62MAKE_FORWARD_VALUE(char *const &, std::string, char const *)
63MAKE_FORWARD_VALUE(char const *const &, std::string, char const *)
64
65#undef MAKE_FORWARD_VALUE
66
67// Copy string literal by pointer.
68template<std::size_t N>
69struct forward_value<char const (&)[N]> {
70 using type = char const *;
71
72 [[nodiscard]] constexpr type operator()(char const (&t)[N]) const noexcept
73 {
74 return static_cast<char const *>(t);
75 }
76};
77
82template<typename T>
83using forward_value_t = typename forward_value<T>::type;
84
85} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:13
typename forward_value< T >::type forward_value_t
Get the storage type of the forward_value functor.
Definition forward_value.hpp:83
Functor for forwarding an forwarding-reference to variable.
Definition forward_value.hpp:29