TrinityCore
advstd.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_ADVSTD_H
19#define TRINITY_ADVSTD_H
20
21#include <version>
22
23#ifdef __cpp_lib_bit_cast
24#include <bit>
25#else
26#include <cstring> // for memcpy
27#endif
28#include <compare>
29
30// this namespace holds implementations of upcoming stdlib features that our c++ version doesn't have yet
31namespace advstd
32{
33// libc++ is missing these two
34[[nodiscard]] constexpr bool is_eq(std::partial_ordering cmp) noexcept { return cmp == 0; }
35[[nodiscard]] constexpr bool is_neq(std::partial_ordering cmp) noexcept { return cmp != 0; }
36
37#ifdef __cpp_lib_bit_cast
38using std::bit_cast;
39#else
40// libstdc++ v10 is missing this
41template <typename To, typename From,
42 std::enable_if_t<std::conjunction_v<
43 std::bool_constant<sizeof(To) == sizeof(From)>,
44 std::is_trivially_copyable<To>,
45 std::is_trivially_copyable<From>>, int> = 0>
46[[nodiscard]] constexpr To bit_cast(From const& from) noexcept
47{
48 To to;
49 std::memcpy(&to, &from, sizeof(To));
50 return to;
51}
52#endif
53}
54
55#endif
Definition: advstd.h:32
constexpr bool is_eq(std::partial_ordering cmp) noexcept
Definition: advstd.h:34
constexpr bool is_neq(std::partial_ordering cmp) noexcept
Definition: advstd.h:35
constexpr To bit_cast(From const &from) noexcept
Definition: advstd.h:46