Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
util.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <memory>
6 
7 namespace inexor {
8 namespace util {
9 
16  template<typename T> std::string to_string(T x) {
17  return fmt << x;
18  }
19 
27  template<typename To, typename From>
28  std::unique_ptr<To> dynamic_pointer_cast(std::unique_ptr<From> &&f) noexcept {
29  To *tp = dynamic_cast<To*>(f.get());
30  if (tp != nullptr) f.release();
31  return std::unique_ptr<To>{ tp };
32  }
33 
50  template<typename T>
52 
53  std::string sep = to_string(sep__);
54 
55  size_t pos = s.rfind(sep);
56  if (pos == std::string::npos) return s;
57 
58  pos += sep.size();
59  if (pos == s.length()) return "";
60 
61  return s.substr(pos);
62  }
63 
71 #define INEXOR_FUNCTION_ALIAS(alias, orig) \
72  template <typename... Args> \
73  auto alias (Args&&... args) \
74  -> decltype( orig(std::forward<Args>(args)...)) { \
75  return orig(std::forward<Args>(args)...); \
76  }
77 
84 #if defined(__GNUC__) && !defined(COMPILER_ICC)
85  #define INEXOR_ATTR_UNUSED __attribute__ ((unused))
86 #else
87  #define INEXOR_ATTR_UNUSED
88 #endif
89 
90 }
91 }
StringFormatter::FmtMark fmt
Marker that starts formatting a string.
Definition: StringFormatter.cpp:5
std::string split_find_last(const std::string &s, T sep__)
Split a string and get the last component.
Definition: util.hpp:51
ICOMMAND * f(float *a, float *b), floatret(*a **b)
std::string to_string(T x)
Convert stuff to a string.
Definition: util.hpp:16
char string[MAXSTRLEN]
cube-strings (char arrays of fixed size).
Definition: cube_types.hpp:18
std::unique_ptr< To > dynamic_pointer_cast(std::unique_ptr< From > &&f) noexcept
Moving dynamic cast for unique_ptr.
Definition: util.hpp:28