TrinityCore
Loading...
Searching...
No Matches
Tuples.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 TRINITYCORE_TUPLES_H
19#define TRINITYCORE_TUPLES_H
20
21#include <tuple>
22
23namespace Trinity
24{
25 template <typename... Ts>
26 constexpr bool is_tuple_v = false;
27
28 template <typename... Ts>
29 constexpr bool is_tuple_v<std::tuple<Ts...>> = true;
30
31 template <typename... Ts>
32 using is_tuple_t = std::bool_constant<is_tuple_v<Ts...>>;
33
34 template <typename T, typename... Us>
35 constexpr bool tuple_has_type_v = false;
36
37 template <typename T, typename... Us>
38 constexpr bool tuple_has_type_v<T, std::tuple<Us...>> = std::disjunction_v<std::is_same<T, Us>...>;
39
40 template <typename T, typename... Us>
41 using tuple_has_type_t = std::bool_constant<tuple_has_type_v<T, Us...>>;
42
43 namespace Impl
44 {
45 template <class T, class Tuple, size_t... I>
46 inline T* new_from_tuple(Tuple&& args, std::index_sequence<I...>)
47 {
48 return new T(std::get<I>(std::forward<Tuple>(args))...);
49 }
50 }
51
52 template <class T, class Tuple>
53 [[nodiscard]] inline T* new_from_tuple(Tuple&& args)
54 {
55 return Impl::new_from_tuple<T>(std::forward<Tuple>(args), std::make_index_sequence<std::tuple_size_v<std::remove_reference_t<Tuple>>>{});
56 }
57
58 template <std::size_t I>
59 inline constexpr auto TupleElement = []<typename Tuple>(Tuple&& tuple) constexpr -> decltype(auto) { return std::get<I>(std::forward<Tuple>(tuple)); };
60}
61
62#endif // TRINITYCORE_TUPLES_H
T * new_from_tuple(Tuple &&args, std::index_sequence< I... >)
Definition Tuples.h:46
constexpr bool tuple_has_type_v
Definition Tuples.h:35
std::bool_constant< tuple_has_type_v< T, Us... > > tuple_has_type_t
Definition Tuples.h:41
constexpr bool is_tuple_v
Definition Tuples.h:26
std::bool_constant< is_tuple_v< Ts... > > is_tuple_t
Definition Tuples.h:32
T * new_from_tuple(Tuple &&args)
Definition Tuples.h:53
constexpr auto TupleElement
Definition Tuples.h:59