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