mdds
Loading...
Searching...
No Matches
global.hpp
1/*************************************************************************
2 *
3 * Copyright (c) 2008-2020 Kohei Yoshida
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following
12 * conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 *
26 ************************************************************************/
27
28#ifndef INCLUDED_MDDS_GLOBAL_HPP
29#define INCLUDED_MDDS_GLOBAL_HPP
30
31#include <exception>
32#include <string>
33#include <memory>
34#include <utility>
35#include <type_traits>
36
47#define MDDS_ASCII(literal) literal, sizeof(literal) - 1
48
57#define MDDS_N_ELEMENTS(name) sizeof(name) / sizeof(name[0])
58
59#ifdef __GNUC__
60#define MDDS_DEPRECATED __attribute__((deprecated))
61#elif defined(_MSC_VER)
62#define MDDS_DEPRECATED __declspec(deprecated)
63#else
64#define MDDS_DEPRECATED
65#endif
66
67#ifndef MDDS_LOOP_UNROLLING
68#define MDDS_LOOP_UNROLLING 1
69#endif
70
71#ifndef MDDS_USE_OPENMP
72#define MDDS_USE_OPENMP 0
73#endif
74
75#if defined(__AVX__) || defined(__AVX2__)
76#ifndef __SSE2__
77#define __SSE2__ 1
78#endif
79#endif
80
81namespace mdds {
82
83class general_error : public ::std::exception
84{
85public:
86 general_error(const ::std::string& msg) : m_msg(msg)
87 {}
88 virtual ~general_error() noexcept
89 {}
90
91 virtual const char* what() const noexcept
92 {
93 return m_msg.c_str();
94 }
95
96private:
97 ::std::string m_msg;
98};
99
101{
102public:
103 invalid_arg_error(const ::std::string& msg) : general_error(msg)
104 {}
105};
106
108{
109public:
110 size_error(const std::string& msg) : general_error(msg)
111 {}
112};
113
115{
116public:
117 type_error(const std::string& msg) : general_error(msg)
118 {}
119};
120
122{
123public:
124 integrity_error(const std::string& msg) : general_error(msg)
125 {}
126};
127
128namespace detail {
129
130template<typename T>
132{
133 using y_type = char;
134 using n_type = long;
135
136 template<typename U>
137 static y_type test(typename U::value_type);
138 template<typename U>
139 static n_type test(...);
140
141public:
142 static constexpr bool value = sizeof(test<T>(0)) == sizeof(y_type);
143};
144
145template<typename T, typename IsConst>
147
148template<typename T>
149struct const_or_not<T, std::true_type>
150{
151 using type = typename std::add_const<T>::type;
152};
153
154template<typename T>
155struct const_or_not<T, std::false_type>
156{
157 using type = T;
158};
159
160template<typename T, bool Const>
161using const_t = typename const_or_not<T, std::bool_constant<Const>>::type;
162
163template<typename T, typename Mutable>
165
166template<typename T>
167struct mutable_or_not<T, std::true_type>
168{
169 using type = T;
170};
171
172template<typename T>
173struct mutable_or_not<T, std::false_type>
174{
175 using type = typename std::add_const<T>::type;
176};
177
178template<typename T, bool Mutable>
179using mutable_t = typename mutable_or_not<T, std::bool_constant<Mutable>>::type;
180
181template<typename T, typename IsConst>
183
184template<typename T>
185struct get_iterator_type<T, std::true_type>
186{
187 using type = typename T::const_iterator;
188};
189
190template<typename T>
191struct get_iterator_type<T, std::false_type>
192{
193 using type = typename T::iterator;
194};
195
196template<int T>
197constexpr bool invalid_static_int()
198{
199 return false;
200}
201
202template<typename T, typename = void>
203struct is_complete : std::false_type
204{
205};
206
207template<typename T>
208struct is_complete<T, std::void_t<decltype(sizeof(T) != 0)>> : std::true_type
209{
210};
211
212} // namespace detail
213
214} // namespace mdds
215
216#endif
Definition global.hpp:132
Definition global.hpp:84
Definition global.hpp:122
Definition global.hpp:101
Definition global.hpp:108
Definition global.hpp:115
Definition global.hpp:146
Definition global.hpp:182
Definition global.hpp:204
Definition global.hpp:164