ge211
ge211_util.h
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 #include <sstream>
6 
7 namespace ge211 {
8 
10 template<class T>
11 std::string to_string(const T& value)
12 {
13  std::ostringstream oss;
14  oss << value;
15  return oss.str();
16 }
17 
18 namespace detail {
19 
20 template<class T>
21 using delete_ptr = std::unique_ptr<T, void (*)(T*)>;
22 
23 template<class T>
24 void no_op_deleter(T*) {}
25 
26 } // end namespace detail
27 
29 template <class T, class U = T>
30 constexpr bool is_nothrow_convertible()
31 {
32  T t{};
33  return noexcept(U(t));
34 }
35 
37 template<class T>
38 constexpr bool is_nothrow_comparable()
39 {
40  T t{};
41  return noexcept(t == t, t != t);
42 }
43 
46 template<class T, class U = T>
47 constexpr bool has_nothrow_arithmetic()
48 {
49  T t{};
50  U u{};
51  return noexcept(t + u, t - u, t * u);
52 }
53 
55 template<class T, class U = T>
56 constexpr bool has_nothrow_division()
57 {
58  T t{};
59  U u{};
60  return noexcept(t / u);
61 }
62 
63 } // end namespace ge211
64 
std::string to_string(const T &value)
Converts any printable type to a std::string.
Definition: ge211_util.h:11
constexpr bool has_nothrow_division()
Can types T and U be used for division without risk of an exception?
Definition: ge211_util.h:56
constexpr bool has_nothrow_arithmetic()
Can types T and U be used for basic arithmetic (addition, subtraction, multiplication) without risk o...
Definition: ge211_util.h:47
The game engine namespace.
Definition: ge211.h:17
constexpr bool is_nothrow_comparable()
Can type T be compared to itself without risk of an exception?
Definition: ge211_util.h:38
constexpr bool is_nothrow_convertible()
Can type T be converted to type U without risk of an exception?
Definition: ge211_util.h:30