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 tt {
12
28template<typename T>
30 using type = std::remove_cvref_t<T>;
31
32 [[nodiscard]] constexpr T &&operator()(std::remove_reference_t<T> &t) const noexcept
33 {
34 return static_cast<T &&>(t);
35 }
36
37 [[nodiscard]] constexpr T &&operator()(std::remove_reference_t<T> &&t) const noexcept
38 {
39 static_assert(!std::is_lvalue_reference_v<T>, "Can not forward an rvalue as an lvalue.");
40 return static_cast<T &&>(t);
41 }
42};
43
44template<size_t N>
45struct forward_value<char const (&)[N]> {
46 using type = char const *;
47
48 [[nodiscard]] constexpr char const *operator()(char const (&t)[N]) const noexcept
49 {
50 return static_cast<char const *>(t);
51 }
52};
53
54template<>
55struct forward_value<std::string_view> {
56 using type = std::string;
57
58 [[nodiscard]] std::string operator()(std::string_view t) const noexcept
59 {
60 return std::string{t};
61 }
62};
63
68template<typename T>
69using forward_value_t = typename forward_value<T>::type;
70
71} // namespace tt
STL namespace.
Functor for forwarding an forwarding-reference to variable.
Definition forward_value.hpp:29