mdds
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
128template<bool B>
129using bool_constant = std::integral_constant<bool, B>;
130
131namespace detail {
132
133template<typename T>
135{
136 using y_type = char;
137 using n_type = long;
138
139 template<typename U>
140 static y_type test(typename U::value_type);
141 template<typename U>
142 static n_type test(...);
143
144public:
145 static constexpr bool value = sizeof(test<T>(0)) == sizeof(y_type);
146};
147
148template<typename T, typename IsConst>
150
151template<typename T>
152struct const_or_not<T, std::true_type>
153{
154 using type = typename std::add_const<T>::type;
155};
156
157template<typename T>
158struct const_or_not<T, std::false_type>
159{
160 using type = T;
161};
162
163template<typename T, bool Const>
164using const_t = typename const_or_not<T, bool_constant<Const>>::type;
165
166template<typename T, typename IsConst>
168
169template<typename T>
170struct get_iterator_type<T, std::true_type>
171{
172 using type = typename T::const_iterator;
173};
174
175template<typename T>
176struct get_iterator_type<T, std::false_type>
177{
178 using type = typename T::iterator;
179};
180
181template<int T>
182constexpr bool invalid_static_int()
183{
184 return false;
185}
186
187template<typename T, typename = void>
188struct is_complete : std::false_type
189{
190};
191
192template<typename T>
193struct is_complete<T, std::void_t<decltype(sizeof(T) != 0)>> : std::true_type
194{
195};
196
197} // namespace detail
198
199} // namespace mdds
200
201#endif
Definition: global.hpp:135
Definition: global.hpp:84
Definition: global.hpp:122
Definition: global.hpp:101
Definition: global.hpp:108
Definition: global.hpp:115
Definition: global.hpp:149
Definition: global.hpp:167
Definition: global.hpp:189