Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
Globals.hh
Go to the documentation of this file.
1//
2// MIT License
3// Copyright (c) 2020 Jonathan R. Madsen
4// Permission is hereby granted, free of charge, to any person obtaining a copy
5// of this software and associated documentation files (the "Software"), to deal
6// in the Software without restriction, including without limitation the rights
7// to use, copy, modify, merge, publish, distribute, sublicense, and
8// copies of the Software, and to permit persons to whom the Software is
9// furnished to do so, subject to the following conditions:
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
12// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
13// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
15// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
17// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18//
19
20#pragma once
21
22#ifndef FALSE
23# define FALSE 0
24#endif
25
26#ifndef TRUE
27# define TRUE 1
28#endif
29
30#include <algorithm> // Retrieve definitions of min/max
31
32// Include base types
33#include "PTL/Types.hh"
34
35// Global utility functions
36#include "PTL/Utility.hh"
37
38#include <initializer_list>
39#include <tuple>
40#include <type_traits>
41#include <utility>
42
43#if !defined(PTL_FOLD_EXPRESSION)
44# define PTL_FOLD_EXPRESSION(...) \
45 ::PTL::mpl::consume_parameters( \
46 ::std::initializer_list<int>{ (__VA_ARGS__, 0)... })
47#endif
48
49namespace PTL
50{
51template <typename T>
52using decay_t = typename std::decay<T>::type;
53
54template <bool B, typename T = void>
55using enable_if_t = typename std::enable_if<B, T>::type;
56
57// for pre-C++14 tuple expansion to arguments
58namespace mpl
59{
60//--------------------------------------------------------------------------------------//
61
62template <typename... Args>
63void
65{}
66
67//--------------------------------------------------------------------------------------//
68
69namespace impl
70{
71//--------------------------------------------------------------------------------------//
72// Stores a tuple of indices. Used by tuple and pair, and by bind() to
73// extract the elements in a tuple.
74template <size_t... Indexes>
76{};
77
78// Concatenates two Index_tuples.
79template <typename Itup1, typename Itup2>
80struct Itup_cat;
81
82template <size_t... Ind1, size_t... Ind2>
83struct Itup_cat<Index_tuple<Ind1...>, Index_tuple<Ind2...>>
84{
85 using __type = Index_tuple<Ind1..., (Ind2 + sizeof...(Ind1))...>;
86};
87
88// Builds an Index_tuple<0, 1, 2, ..., NumT-1>.
89template <size_t NumT>
91: Itup_cat<typename Build_index_tuple<NumT / 2>::__type,
92 typename Build_index_tuple<NumT - NumT / 2>::__type>
93{};
94
95template <>
97{
99};
100
101template <>
103{
105};
106
107/// Class template integer_sequence
108template <typename Tp, Tp... Idx>
110{
111 typedef Tp value_type;
112 static constexpr size_t size() noexcept { return sizeof...(Idx); }
113};
114
115template <typename Tp, Tp NumT, typename ISeq = typename Build_index_tuple<NumT>::__type>
117
118template <typename Tp, Tp NumT, size_t... Idx>
119struct Make_integer_sequence<Tp, NumT, Index_tuple<Idx...>>
120{
121 static_assert(NumT >= 0, "Cannot make integer sequence of negative length");
122
124};
125
126/// Alias template make_integer_sequence
127template <typename Tp, Tp NumT>
129
130/// Alias template index_sequence
131template <size_t... Idx>
132using index_sequence = integer_sequence<size_t, Idx...>;
133
134/// Alias template make_index_sequence
135template <size_t NumT>
137
138/// Alias template index_sequence_for
139template <typename... Types>
140using index_sequence_for = make_index_sequence<sizeof...(Types)>;
141
142template <size_t Idx, typename Tup>
143using index_type_t = decay_t<decltype(std::get<Idx>(std::declval<Tup>()))>;
144
145template <typename FnT, typename TupleT, size_t... Idx>
146static inline auto
147apply(FnT&& __f, TupleT&& __t, impl::index_sequence<Idx...>)
148 -> decltype(std::forward<FnT>(__f)(std::get<Idx>(__t)...))
149{
150 return std::forward<FnT>(__f)(std::get<Idx>(__t)...);
151}
152
153//--------------------------------------------------------------------------------------//
154
155} // namespace impl
156
157//--------------------------------------------------------------------------------------//
158
159/// Alias template index_sequence
160template <size_t... Idx>
162
163/// Alias template make_index_sequence
164template <size_t NumT>
166
167/// Alias template index_sequence_for
168template <typename... Types>
170
171template <typename FnT, typename TupleT>
172static inline void
173apply(FnT&& __f, TupleT&& __t)
174{
175 constexpr auto N = std::tuple_size<TupleT>::value;
176 impl::apply(std::forward<FnT>(__f), std::forward<TupleT>(__t),
178}
179
180//--------------------------------------------------------------------------------------//
181
182} // namespace mpl
183
184namespace thread_pool
185{
186namespace state
187{
188static const short STARTED = 0;
189static const short PARTIAL = 1;
190static const short STOPPED = 2;
191static const short NONINIT = 3;
192
193} // namespace state
194} // namespace thread_pool
195
196//--------------------------------------------------------------------------------------//
197
198} // namespace PTL
typename Make_integer_sequence< Tp, NumT >::__type make_integer_sequence
Alias template make_integer_sequence.
Definition: Globals.hh:128
make_integer_sequence< size_t, NumT > make_index_sequence
Alias template make_index_sequence.
Definition: Globals.hh:136
decay_t< decltype(std::get< Idx >(std::declval< Tup >()))> index_type_t
Definition: Globals.hh:143
make_index_sequence< sizeof...(Types)> index_sequence_for
Alias template index_sequence_for.
Definition: Globals.hh:140
void consume_parameters(Args &&...)
Definition: Globals.hh:64
impl::make_integer_sequence< size_t, NumT > make_index_sequence
Alias template make_index_sequence.
Definition: Globals.hh:165
impl::make_index_sequence< sizeof...(Types)> index_sequence_for
Alias template index_sequence_for.
Definition: Globals.hh:169
Definition: AutoLock.hh:254
typename std::decay< T >::type decay_t
Definition: Globals.hh:52
typename std::enable_if< B, T >::type enable_if_t
Definition: Globals.hh:55
integer_sequence< Tp, static_cast< Tp >(Idx)... > __type
Definition: Globals.hh:123
Class template integer_sequence.
Definition: Globals.hh:110
static constexpr size_t size() noexcept
Definition: Globals.hh:112