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#define MDDS_DEPRECATED [[deprecated]]
36
37#ifndef MDDS_LOOP_UNROLLING
38#define MDDS_LOOP_UNROLLING 1
39#endif
40
41#ifndef MDDS_USE_OPENMP
42#define MDDS_USE_OPENMP 0
43#endif
44
45#if defined(__AVX__) || defined(__AVX2__)
46#ifndef __SSE2__
47#define __SSE2__ 1
48#endif
49#endif
50
51namespace mdds {
52
53class general_error : public ::std::exception
54{
55public:
56 general_error(const ::std::string& msg) : m_msg(msg)
57 {}
58 virtual ~general_error() noexcept
59 {}
60
61 virtual const char* what() const noexcept
62 {
63 return m_msg.c_str();
64 }
65
66private:
67 ::std::string m_msg;
68};
69
70class invalid_arg_error : public general_error
71{
72public:
73 invalid_arg_error(const ::std::string& msg) : general_error(msg)
74 {}
75};
76
77class size_error : public general_error
78{
79public:
80 size_error(const std::string& msg) : general_error(msg)
81 {}
82};
83
84class type_error : public general_error
85{
86public:
87 type_error(const std::string& msg) : general_error(msg)
88 {}
89};
90
91class integrity_error : public general_error
92{
93public:
94 integrity_error(const std::string& msg) : general_error(msg)
95 {}
96};
97
98namespace detail {
99
100template<typename T>
101concept has_value_type = requires { typename T::value_type; };
102
103template<typename T, typename IsConst>
105
106template<typename T>
107struct const_or_not<T, std::true_type>
108{
109 using type = typename std::add_const<T>::type;
110};
111
112template<typename T>
113struct const_or_not<T, std::false_type>
114{
115 using type = T;
116};
117
118template<typename T, bool Const>
119using const_t = typename const_or_not<T, std::bool_constant<Const>>::type;
120
121template<typename T, typename Mutable>
123
124template<typename T>
125struct mutable_or_not<T, std::true_type>
126{
127 using type = T;
128};
129
130template<typename T>
131struct mutable_or_not<T, std::false_type>
132{
133 using type = typename std::add_const<T>::type;
134};
135
136template<typename T, bool Mutable>
137using mutable_t = typename mutable_or_not<T, std::bool_constant<Mutable>>::type;
138
139template<typename T, typename IsConst>
141
142template<typename T>
143struct get_iterator_type<T, std::true_type>
144{
145 using type = typename T::const_iterator;
146};
147
148template<typename T>
149struct get_iterator_type<T, std::false_type>
150{
151 using type = typename T::iterator;
152};
153
154template<int T>
155constexpr bool invalid_static_int()
156{
157 return false;
158}
159
168template<typename T>
169concept is_complete = requires { sizeof(T); };
170
171} // namespace detail
172
173} // namespace mdds
Definition global.hpp:101
Definition global.hpp:169
Definition global.hpp:104
Definition global.hpp:140
Definition global.hpp:122