mdds
global.hpp
1 // SPDX-FileCopyrightText: 2008 - 2025 Kohei Yoshida
2 //
3 // SPDX-License-Identifier: MIT
4 
5 #pragma once
6 
7 #include <exception>
8 #include <string>
9 #include <memory>
10 #include <utility>
11 #include <type_traits>
12 
23 #define MDDS_ASCII(literal) literal, sizeof(literal) - 1
24 
33 #define MDDS_N_ELEMENTS(name) sizeof(name) / sizeof(name[0])
34 
35 #ifdef __GNUC__
36 #define MDDS_DEPRECATED __attribute__((deprecated))
37 #elif defined(_MSC_VER)
38 #define MDDS_DEPRECATED __declspec(deprecated)
39 #else
40 #define MDDS_DEPRECATED
41 #endif
42 
43 #ifndef MDDS_LOOP_UNROLLING
44 #define MDDS_LOOP_UNROLLING 1
45 #endif
46 
47 #ifndef MDDS_USE_OPENMP
48 #define MDDS_USE_OPENMP 0
49 #endif
50 
51 #if defined(__AVX__) || defined(__AVX2__)
52 #ifndef __SSE2__
53 #define __SSE2__ 1
54 #endif
55 #endif
56 
57 namespace mdds {
58 
59 class general_error : public ::std::exception
60 {
61 public:
62  general_error(const ::std::string& msg) : m_msg(msg)
63  {}
64  virtual ~general_error() noexcept
65  {}
66 
67  virtual const char* what() const noexcept
68  {
69  return m_msg.c_str();
70  }
71 
72 private:
73  ::std::string m_msg;
74 };
75 
77 {
78 public:
79  invalid_arg_error(const ::std::string& msg) : general_error(msg)
80  {}
81 };
82 
83 class size_error : public general_error
84 {
85 public:
86  size_error(const std::string& msg) : general_error(msg)
87  {}
88 };
89 
90 class type_error : public general_error
91 {
92 public:
93  type_error(const std::string& msg) : general_error(msg)
94  {}
95 };
96 
98 {
99 public:
100  integrity_error(const std::string& msg) : general_error(msg)
101  {}
102 };
103 
104 namespace detail {
105 
106 template<typename T>
108 {
109  using y_type = char;
110  using n_type = long;
111 
112  template<typename U>
113  static y_type test(typename U::value_type);
114  template<typename U>
115  static n_type test(...);
116 
117 public:
118  static constexpr bool value = sizeof(test<T>(0)) == sizeof(y_type);
119 };
120 
121 template<typename T, typename IsConst>
123 
124 template<typename T>
125 struct const_or_not<T, std::true_type>
126 {
127  using type = typename std::add_const<T>::type;
128 };
129 
130 template<typename T>
131 struct const_or_not<T, std::false_type>
132 {
133  using type = T;
134 };
135 
136 template<typename T, bool Const>
137 using const_t = typename const_or_not<T, std::bool_constant<Const>>::type;
138 
139 template<typename T, typename Mutable>
141 
142 template<typename T>
143 struct mutable_or_not<T, std::true_type>
144 {
145  using type = T;
146 };
147 
148 template<typename T>
149 struct mutable_or_not<T, std::false_type>
150 {
151  using type = typename std::add_const<T>::type;
152 };
153 
154 template<typename T, bool Mutable>
155 using mutable_t = typename mutable_or_not<T, std::bool_constant<Mutable>>::type;
156 
157 template<typename T, typename IsConst>
159 
160 template<typename T>
161 struct get_iterator_type<T, std::true_type>
162 {
163  using type = typename T::const_iterator;
164 };
165 
166 template<typename T>
167 struct get_iterator_type<T, std::false_type>
168 {
169  using type = typename T::iterator;
170 };
171 
172 template<int T>
173 constexpr bool invalid_static_int()
174 {
175  return false;
176 }
177 
178 template<typename T, typename = void>
179 struct is_complete : std::false_type
180 {
181 };
182 
183 template<typename T>
184 struct is_complete<T, std::void_t<decltype(sizeof(T) != 0)>> : std::true_type
185 {
186 };
187 
188 } // namespace detail
189 
190 } // namespace mdds
Definition: global.hpp:83
Definition: global.hpp:107
Definition: global.hpp:90
Definition: global.hpp:179
Definition: global.hpp:76
Definition: global.hpp:158
Definition: global.hpp:59
Definition: global.hpp:122
Definition: global.hpp:140
Definition: cref_wrapper.hpp:12
Definition: global.hpp:97