mdds
Loading...
Searching...
No Matches
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
57namespace mdds {
58
59class general_error : public ::std::exception
60{
61public:
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
72private:
73 ::std::string m_msg;
74};
75
76class invalid_arg_error : public general_error
77{
78public:
79 invalid_arg_error(const ::std::string& msg) : general_error(msg)
80 {}
81};
82
83class size_error : public general_error
84{
85public:
86 size_error(const std::string& msg) : general_error(msg)
87 {}
88};
89
90class type_error : public general_error
91{
92public:
93 type_error(const std::string& msg) : general_error(msg)
94 {}
95};
96
97class integrity_error : public general_error
98{
99public:
100 integrity_error(const std::string& msg) : general_error(msg)
101 {}
102};
103
104namespace detail {
105
106template<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
117public:
118 static constexpr bool value = sizeof(test<T>(0)) == sizeof(y_type);
119};
120
121template<typename T, typename IsConst>
123
124template<typename T>
125struct const_or_not<T, std::true_type>
126{
127 using type = typename std::add_const<T>::type;
128};
129
130template<typename T>
131struct const_or_not<T, std::false_type>
132{
133 using type = T;
134};
135
136template<typename T, bool Const>
137using const_t = typename const_or_not<T, std::bool_constant<Const>>::type;
138
139template<typename T, typename Mutable>
141
142template<typename T>
143struct mutable_or_not<T, std::true_type>
144{
145 using type = T;
146};
147
148template<typename T>
149struct mutable_or_not<T, std::false_type>
150{
151 using type = typename std::add_const<T>::type;
152};
153
154template<typename T, bool Mutable>
155using mutable_t = typename mutable_or_not<T, std::bool_constant<Mutable>>::type;
156
157template<typename T, typename IsConst>
159
160template<typename T>
161struct get_iterator_type<T, std::true_type>
162{
163 using type = typename T::const_iterator;
164};
165
166template<typename T>
167struct get_iterator_type<T, std::false_type>
168{
169 using type = typename T::iterator;
170};
171
172template<int T>
173constexpr bool invalid_static_int()
174{
175 return false;
176}
177
178template<typename T, typename = void>
179struct is_complete : std::false_type
180{
181};
182
183template<typename T>
184struct 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:108
Definition global.hpp:122
Definition global.hpp:158
Definition global.hpp:180
Definition global.hpp:140