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 
81 namespace mdds {
82 
83 class general_error : public ::std::exception
84 {
85 public:
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 
96 private:
97  ::std::string m_msg;
98 };
99 
101 {
102 public:
103  invalid_arg_error(const ::std::string& msg) : general_error(msg)
104  {}
105 };
106 
107 class size_error : public general_error
108 {
109 public:
110  size_error(const std::string& msg) : general_error(msg)
111  {}
112 };
113 
114 class type_error : public general_error
115 {
116 public:
117  type_error(const std::string& msg) : general_error(msg)
118  {}
119 };
120 
122 {
123 public:
124  integrity_error(const std::string& msg) : general_error(msg)
125  {}
126 };
127 
128 namespace detail {
129 
130 template<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 
141 public:
142  static constexpr bool value = sizeof(test<T>(0)) == sizeof(y_type);
143 };
144 
145 template<typename T, typename IsConst>
147 
148 template<typename T>
149 struct const_or_not<T, std::true_type>
150 {
151  using type = typename std::add_const<T>::type;
152 };
153 
154 template<typename T>
155 struct const_or_not<T, std::false_type>
156 {
157  using type = T;
158 };
159 
160 template<typename T, bool Const>
161 using const_t = typename const_or_not<T, std::bool_constant<Const>>::type;
162 
163 template<typename T, typename Mutable>
165 
166 template<typename T>
167 struct mutable_or_not<T, std::true_type>
168 {
169  using type = T;
170 };
171 
172 template<typename T>
173 struct mutable_or_not<T, std::false_type>
174 {
175  using type = typename std::add_const<T>::type;
176 };
177 
178 template<typename T, bool Mutable>
179 using mutable_t = typename mutable_or_not<T, std::bool_constant<Mutable>>::type;
180 
181 template<typename T, typename IsConst>
183 
184 template<typename T>
185 struct get_iterator_type<T, std::true_type>
186 {
187  using type = typename T::const_iterator;
188 };
189 
190 template<typename T>
191 struct get_iterator_type<T, std::false_type>
192 {
193  using type = typename T::iterator;
194 };
195 
196 template<int T>
197 constexpr bool invalid_static_int()
198 {
199  return false;
200 }
201 
202 template<typename T, typename = void>
203 struct is_complete : std::false_type
204 {
205 };
206 
207 template<typename T>
208 struct 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:107
Definition: global.hpp:131
Definition: global.hpp:114
Definition: global.hpp:203
Definition: global.hpp:100
Definition: global.hpp:182
Definition: global.hpp:83
Definition: global.hpp:146
Definition: global.hpp:164
Definition: flat_segment_tree.hpp:46
Definition: global.hpp:121