fennec
Loading...
Searching...
No Matches
utility.h
Go to the documentation of this file.
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
30
31#ifndef FENNEC_LANG_UTILITY_H
32#define FENNEC_LANG_UTILITY_H
33
61
64
65namespace fennec
66{
67
75template<typename T> constexpr T&& forward(remove_reference_t<T>& x) noexcept {
76 return static_cast<T&&>(x);
77}
78
79// specialization for T&&
80template<typename T> constexpr T&& forward(remove_reference_t<T>&& x) noexcept {
81 return static_cast<T&&>(x);
82}
83
84
92template<typename T> constexpr remove_reference_t<T>&& move(T&& x) noexcept {
93 return static_cast<remove_reference_t<T>&&>(x);
94}
95
96
104template<typename T> constexpr const remove_reference_t<T>& copy(T&& x) noexcept {
105 return x;
106}
107
113template<typename T> requires is_fundamental_v<T>
114constexpr void swap(T& x, T& y) noexcept {
115 T a = x;
116 x = y;
117 y = a;
118}
119
125template<typename T> constexpr void swap(T& x, T& y) noexcept {
126#if FENNEC_COMPILER_GCC
127#pragma GCC diagnostic push
128#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
129#endif
130
131 T a = fennec::move(x);
132 x = fennec::move(y);
133 y = fennec::move(a);
134
135#if FENNEC_COMPILER_GCC
136#pragma GCC diagnostic pop
137#endif
138}
139
140}
141
142#endif // FENNEC_LANG_UTILITY_H
constexpr genType y()
Definition constants.h:672
Type Traits
Type Transforms
typename remove_reference< T >::type remove_reference_t
shorthand for typename remove_reference<T>::type
Definition type_transforms.h:206
constexpr T && forward(remove_reference_t< T > &x) noexcept
forwards reference types to extend their lifetime
Definition utility.h:75
constexpr const remove_reference_t< T > & copy(T &&x) noexcept
produces an r-value type to indicate x may be "copied"
Definition utility.h:104
constexpr void swap(T &x, T &y) noexcept
Swaps x and y.
Definition utility.h:114
constexpr remove_reference_t< T > && move(T &&x) noexcept
produces an x-value type to indicate x may be "moved"
Definition utility.h:92