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#pragma once
6
7#include "../macros.hpp"
8#include <type_traits>
9#include <string>
10#include <string_view>
11
12hi_export_module(hikogui.utility.forward_value);
13
14hi_export namespace hi::inline v1 {
15
31template<typename T>
33 using type = std::remove_cvref_t<T>;
34
35 [[nodiscard]] type operator()(T const &t) const noexcept
36 {
37 return t;
38 }
39};
40
41#define HI_X(TEMPLATE_TYPE, RETURN_TYPE, ARGUMENT_TYPE) \
42 template<> \
43 struct forward_value<TEMPLATE_TYPE> { \
44 using type = RETURN_TYPE; \
45\
46 [[nodiscard]] type operator()(ARGUMENT_TYPE t) const noexcept \
47 { \
48 return type{t}; \
49 } \
50 };
51
52// Copy string_view by string value.
53HI_X(std::string_view, std::string, std::string_view const &)
54HI_X(std::string_view const, std::string, std::string_view const &)
55HI_X(std::string_view &, std::string, std::string_view const &)
56HI_X(std::string_view const &, std::string, std::string_view const &)
57
58// Copy char pointers by string value.
59HI_X(char *, std::string, char const *)
60HI_X(char const *, std::string, char const *)
61HI_X(char *const, std::string, char const *)
62HI_X(char const *const, std::string, char const *)
63HI_X(char *&, std::string, char const *)
64HI_X(char const *&, std::string, char const *)
65HI_X(char *const &, std::string, char const *)
66HI_X(char const *const &, std::string, char const *)
67
68#undef HI_X
69
70// Copy string literal by pointer.
71template<std::size_t N>
72struct forward_value<char const (&)[N]> {
73 using type = char const *;
74
75 [[nodiscard]] constexpr type operator()(char const (&t)[N]) const noexcept
76 {
77 return static_cast<char const *>(t);
78 }
79};
80
85template<typename T>
86using forward_value_t = typename forward_value<T>::type;
87
88} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
typename forward_value< T >::type forward_value_t
Get the storage type of the forward_value functor.
Definition forward_value.hpp:86
Functor for forwarding an forwarding-reference to variable.
Definition forward_value.hpp:32