Silicium
config.hpp
Go to the documentation of this file.
1 #ifndef SILICIUM_SILICIUM_CONFIG_HPP
2 #define SILICIUM_SILICIUM_CONFIG_HPP
3 
4 #include <memory>
5 #include <stdexcept>
6 #include <boost/config.hpp>
7 #include <boost/cstdint.hpp>
8 #include <boost/version.hpp>
9 #include <boost/preprocessor/if.hpp>
10 
11 #if defined(__GNUC__)
12 # define SILICIUM_GCC ((__GNUC__ * 100) + __GNUC_MINOR__)
13 #else
14 # define SILICIUM_GCC 0
15 #endif
16 
17 #ifdef _MSC_VER
18 # define SILICIUM_COMPILER_CXX11 1
19 # define SILICIUM_COMPILER_CXX14 1
20 #elif __cplusplus > 201103L
21 # define SILICIUM_COMPILER_CXX11 1
22 # define SILICIUM_COMPILER_CXX14 1
23 #elif __cplusplus >= 201103L
24 # define SILICIUM_COMPILER_CXX11 1
25 # define SILICIUM_COMPILER_CXX14 1 /* actually 0, assume 1 for now */
26 #else
27 # define SILICIUM_COMPILER_CXX11 0
28 # define SILICIUM_COMPILER_CXX14 0
29 #endif
30 
31 #ifdef BOOST_NO_EXCEPTIONS
32 # define SILICIUM_HAS_EXCEPTIONS 0
33 #else
34 # define SILICIUM_HAS_EXCEPTIONS 1
35 #endif
36 
37 #if defined(NDEBUG) || !SILICIUM_HAS_EXCEPTIONS
38 # ifdef _MSC_VER
39 # define SILICIUM_UNREACHABLE() __assume(false)
40 # else
41 # define SILICIUM_UNREACHABLE() __builtin_unreachable()
42 # endif
43 #else
44 # define SILICIUM_UNREACHABLE() throw ::std::logic_error("unreachable " __FILE__ ":" BOOST_STRINGIZE(__LINE__))
45 #endif
46 
47 #if (defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 408)) || defined(__clang__) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
48 # define SILICIUM_COMPILER_GENERATES_MOVES 1
49 #else
50 # define SILICIUM_COMPILER_GENERATES_MOVES 0
51 #endif
52 
53 #if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 408) || defined(__clang__) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
54 # define SILICIUM_COMPILER_HAS_WORKING_NOEXCEPT 1
55 #else
56 # define SILICIUM_COMPILER_HAS_WORKING_NOEXCEPT 0
57 #endif
58 
59 #ifdef _MSC_VER
60 # define SILICIUM_NORETURN __declspec(noreturn)
61 #else
62 // GCC
63 # define SILICIUM_NORETURN __attribute__ ((__noreturn__))
64 #endif
65 
66 #if (defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 408)) || defined(__clang__) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
67 # define SILICIUM_COMPILER_HAS_RVALUE_THIS_QUALIFIER 1
68 #else
69 # define SILICIUM_COMPILER_HAS_RVALUE_THIS_QUALIFIER 0
70 #endif
71 
72 #if (defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 408) && SILICIUM_COMPILER_CXX14) || defined(__clang__) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
73 # define SILICIUM_COMPILER_HAS_AUTO_RETURN_TYPE 1
74 #else
75 # define SILICIUM_COMPILER_HAS_AUTO_RETURN_TYPE 0
76 #endif
77 
78 #if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 408) || defined(__clang__) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
79 # define SILICIUM_COMPILER_HAS_EXTENDED_CAPTURE 1
80 #else
81 # define SILICIUM_COMPILER_HAS_EXTENDED_CAPTURE 0
82 #endif
83 
84 #if SILICIUM_COMPILER_HAS_EXTENDED_CAPTURE
85 # define SILICIUM_CAPTURE_EXPRESSION(name, value) name = value
86 #else
87 # define SILICIUM_CAPTURE_EXPRESSION(name, value) name
88 #endif
89 
90 #if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 407) || defined(__clang__) || defined(_MSC_VER)
91 # define SILICIUM_COMPILER_HAS_VARIADIC_PACK_EXPANSION 1
92 #else
93 # define SILICIUM_COMPILER_HAS_VARIADIC_PACK_EXPANSION 0
94 #endif
95 
96 #if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 407) || defined(__clang__) || (defined(_MSC_VER) && (_MSC_VER != 1900)) //VS 2015 has a buggy variadic template using
97 # define SILICIUM_COMPILER_HAS_USING 1
98 #else
99 # define SILICIUM_COMPILER_HAS_USING 0
100 #endif
101 
102 #if defined(_MSC_VER) && (_MSC_VER < 1900)
103 # define SILICIUM_COMPILER_HAS_CXX11_UNION 0
104 #else
105 # define SILICIUM_COMPILER_HAS_CXX11_UNION 1
106 #endif
107 
108 #ifdef BOOST_DELETED_FUNCTION
109 # define SILICIUM_DELETED_FUNCTION BOOST_DELETED_FUNCTION
110 #else
111 # define SILICIUM_DELETED_FUNCTION(f) private: f;
112 #endif
113 
114 #define SILICIUM_DISABLE_COPY(struct_name) \
115  SILICIUM_DELETED_FUNCTION(struct_name(struct_name const &)) \
116  SILICIUM_DELETED_FUNCTION(struct_name &operator = (struct_name const &))
117 
118 #define SILICIUM_DEFAULT_NOEXCEPT_MOVE(struct_name) \
119  struct_name(struct_name &&) BOOST_NOEXCEPT = default; \
120  struct_name &operator = (struct_name &&) BOOST_NOEXCEPT = default;
121 
122 #define SILICIUM_DEFAULT_MOVE(struct_name) \
123  struct_name(struct_name &&) = default; \
124  struct_name &operator = (struct_name &&) = default;
125 
126 #define SILICIUM_DEFAULT_COPY(struct_name) \
127  struct_name(struct_name const &) = default; \
128  struct_name &operator = (struct_name const &) = default;
129 
130 #ifdef _MSC_VER
131 # define SILICIUM_DEPRECATED __declspec(deprecated)
132 #else
133 # define SILICIUM_DEPRECATED __attribute__((deprecated))
134 #endif
135 
136 #if defined(__GNUC__) && (__GNUC__ <= 4) && (__GNUC__ < 4 || __GNUC_MINOR__ <= 6)
137 # define SILICIUM_OVERRIDE
138 # define SILICIUM_FINAL
139 #else
140 # define SILICIUM_OVERRIDE override
141 # define SILICIUM_FINAL final
142 #endif
143 
144 #ifdef _MSC_VER
145 # define SILICIUM_USE_RESULT _Check_return_
146 #else
147 # define SILICIUM_USE_RESULT __attribute__((warn_unused_result))
148 #endif
149 
150 //TODO
151 #define SILICIUM_CXX14_CONSTEXPR
152 
153 #define SILICIUM_IF(condition, value) BOOST_PP_IF(condition, value, BOOST_PP_EMPTY())
154 #define SILICIUM_IF_NOT(condition, value) BOOST_PP_IF(condition, BOOST_PP_EMPTY(), value)
155 
156 #define SILICIUM_MOVE_IF_COMPILER_LACKS_RVALUE_QUALIFIERS(should_be_rvalue) BOOST_PP_IF(SILICIUM_COMPILER_HAS_RVALUE_THIS_QUALIFIER, (should_be_rvalue), std::move((should_be_rvalue)))
157 
158 namespace Si
159 {
160  struct nothing
161  {
162  BOOST_CONSTEXPR nothing() BOOST_NOEXCEPT
163  {
164  }
165  };
166 
167  inline bool operator == (nothing const &, nothing const &)
168  {
169  return true;
170  }
171 
172  template <class T, class ...Args>
173  auto make_unique(Args &&...args) -> std::unique_ptr<T>
174  {
175  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
176  }
177 
178  template <class To, class From>
179  To function_ptr_cast(From from)
180  {
181  //TODO: check that the cast makes sense
182 #ifdef __GNUC__
183  //silence Warnung: ISO C++ forbids casting between pointer-to-function and pointer-to-object [enabled by default]
184  __extension__
185 #endif
186  To result = reinterpret_cast<To>(from);
187  return result;
188  }
189 
190 #if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 407) || defined(__clang__)
191 #define SILICIUM_HAS_PROPER_COPY_TRAITS 1
192 }
193 #include <type_traits>
194 namespace Si
195 {
196  using std::is_copy_constructible;
197  using std::is_copy_assignable;
198 #elif BOOST_VERSION >= 105500 //1.55
199 #define SILICIUM_HAS_PROPER_COPY_TRAITS 1
200 }
201 #include <boost/type_traits/is_copy_constructible.hpp>
202 #include <boost/type_traits/is_convertible.hpp>
203 
204 #if SILICIUM_HAS_EXCEPTIONS
205 # include <future>
206 #endif
207 
208 namespace Si
209 {
210  using boost::is_copy_constructible;
211 #if SILICIUM_HAS_EXCEPTIONS
212  template <class T>
213  struct is_copy_constructible<std::future<T>> : std::false_type
214  {
215  };
216 #endif
217  template <class T>
218  struct is_copy_assignable : std::true_type
219  {
220  };
221 #if SILICIUM_HAS_EXCEPTIONS
222  template <class T>
223  struct is_copy_assignable<std::future<T>> : std::false_type
224  {
225  };
226 #endif
227  template <class T, class D>
228  struct is_copy_assignable<std::unique_ptr<T, D>> : std::false_type
229  {
230  };
231 #else
232 #define SILICIUM_HAS_PROPER_COPY_TRAITS 0
233  template <class T>
234  struct is_copy_constructible : std::true_type
235  {
236  };
237  template <class T>
238  struct is_copy_assignable : std::true_type
239  {
240  };
241 #endif
242 
243 #if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 407) || defined(__clang__) || defined(_MSC_VER)
244 }
245 #include <type_traits>
246 namespace Si
247 {
248  using std::is_default_constructible;
249  using std::is_move_assignable;
250  using std::is_move_constructible;
251  using std::is_nothrow_default_constructible;
252  using std::is_nothrow_move_constructible;
253  using std::is_nothrow_move_assignable;
254  using std::is_nothrow_destructible;
255 #else
256  template <class T>
257  struct is_default_constructible : std::conditional<
258  std::is_reference<T>::value,
259  std::false_type,
260  std::is_constructible<T>
261  >::type
262  {
263  };
264  template <class T>
265  struct is_nothrow_default_constructible : std::has_nothrow_default_constructor<T>
266  {
267  };
268  template <class T>
269  struct is_nothrow_move_constructible : std::has_nothrow_copy_constructor<T>
270  {
271  };
272  template <class T>
273  struct is_nothrow_move_assignable : std::has_nothrow_copy_assign<T>
274  {
275  };
276  template <class T>
277  struct is_nothrow_destructible : std::true_type
278  {
279  };
280  template <class T>
282  {
283  };
284  template <class T>
285  struct is_move_assignable<std::unique_ptr<T>> : std::true_type
286  {
287  };
288  template <class T>
290  {
291  };
292  template <class T>
293  struct is_move_constructible<std::unique_ptr<T>> : std::true_type
294  {
295  };
296 #endif
297 
298 #if BOOST_VERSION <= 105400
299 # if defined(_MSC_VER) && (_MSC_VER < 1900)
300  typedef std::size_t uintptr_t;
301 # else
303 # endif
304 #else
305  typedef boost::uintptr_t uintptr_t;
306 #endif
307 }
308 
309 #endif
Definition: config.hpp:160
Definition: config.hpp:265
Definition: config.hpp:277
Definition: absolute_path.hpp:352
Definition: absolute_path.hpp:19
auto make_unique(Args &&...args) -> std::unique_ptr< T >
Definition: config.hpp:173
Definition: config.hpp:257
Definition: config.hpp:238
SILICIUM_USE_RESULT bool operator==(absolute_path const &left, ComparableToPath const &right)
Definition: absolute_path.hpp:169
std::uintptr_t uintptr_t
Definition: config.hpp:302
Definition: config.hpp:269
Definition: config.hpp:289
To function_ptr_cast(From from)
Definition: config.hpp:179
Definition: config.hpp:281
BOOST_CONSTEXPR nothing() BOOST_NOEXCEPT
Definition: config.hpp:162
Definition: config.hpp:234
Definition: config.hpp:273