37 #ifndef LIB_META_UTIL_H 38 #define LIB_META_UTIL_H 40 #include "lib/integral.hpp" 51 template <
typename T,
typename D>
66 template <
bool B,
class T =
void>
91 template <
class Cond,
class T =
void>
92 using enable_if =
typename enable_if_c<Cond::value, T>::type;
94 template <
class Cond,
class T =
void>
95 using disable_if =
typename enable_if_c<not Cond::value, T>::type;
105 struct No_t {
char more_than_one[4]; };
118 template<
typename TY>
122 static Yes_t check(
typename ZZ::type *);
124 static Yes_t check(
typename X::Type *);
126 static No_t check(...);
129 static const bool value = (
sizeof(Yes_t)==
sizeof(check<TY>(0)));
135 struct has_TypeResult : std::bool_constant<_DetectNested_TypeResult<X>::value> { };
140 template<
typename...>
145 template<
typename X,
typename...XS>
152 template<
typename...XS>
158 template<
class SELF,
typename ...ARGS>
175 static Yes_t check_implicit(std::string);
176 static Yes_t check_implicit(std::string_view);
177 static Yes_t check_implicit(
const char*);
178 static No_t check_implicit(...);
181 template<
class XX,
int i = sizeof(&XX::operator std::
string)>
186 static Yes_t check_explicit(
Probe<XX> * );
188 static No_t check_explicit(...);
191 static const bool value = (
sizeof(Yes_t)==
sizeof(check_implicit (std::declval<X>())))
192 or (
sizeof(Yes_t)==
sizeof(check_explicit<X>(0)));
207 template<
typename TY>
211 static Yes_t check(
typename X::List *);
213 static No_t check(...);
216 static const bool value = (
sizeof(Yes_t)==
sizeof(check<TY>(0)));
223 template<
typename FUN>
226 template<
typename FF,
227 typename SEL = decltype(&FF::operator())>
234 static No_t check(...);
237 static const bool value = (
sizeof(Yes_t)==
sizeof(check<FUN>(0)));
247 template<
class BAS,
size_t m=0>
295 extern const std::string FUNCTION_INDICATOR;
296 extern const std::string FAILURE_INDICATOR;
297 extern const std::string BOTTOM_INDICATOR;
298 extern const std::string VOID_INDICATOR;
300 extern const std::string BOOL_FALSE_STR;
301 extern const std::string BOOL_TRUE_STR;
323 template<
typename TY>
327 auto mangledType = obj?
typeid(*obj).name()
329 return humanReadableTypeID (mangledType);
332 {
return FAILURE_INDICATOR; }
334 template<
typename TY>
335 inline disable_if<std::is_pointer<TY>,
337 typeStr (TY
const& ref) noexcept
345 return VOID_INDICATOR;
355 template<
typename TY>
357 typeSymbol (TY
const* obj =
nullptr)
359 auto mangledType = obj?
typeid(*obj).name()
361 return primaryTypeComponent (mangledType);
364 template<
typename TY>
365 inline disable_if<std::is_pointer<TY>,
367 typeSymbol (TY
const& ref)
369 return typeSymbol (&ref);
379 using lib::meta::typeStr;
380 using lib::meta::FAILURE_INDICATOR;
381 using lib::meta::BOTTOM_INDICATOR;
398 template<
typename X,
typename COND =
void>
402 invoke (X
const& x) noexcept
403 try {
return "«"+typeStr(x)+
"»"; }
404 catch(...) {
return FAILURE_INDICATOR; }
411 invoke (X
const& val) noexcept
412 try {
return std::string(val); }
413 catch(...) {
return FAILURE_INDICATOR; }
422 struct StringConv<X*, lib::meta::disable_if<std::__or_<std::is_same<std::remove_cv_t<X>,
char>
423 ,std::is_same<std::remove_cv_t<X>,
void>
427 invoke (X
const* ptr) noexcept
429 : BOTTOM_INDICATOR +
"«"+typeStr(ptr)+
"»";
431 catch(...) {
return FAILURE_INDICATOR; }
446 return yes? lib::meta::BOOL_TRUE_STR
447 : lib::meta::BOOL_FALSE_STR;
452 std::string showFloat (
float) noexcept;
464 std::string showSize (
size_t) noexcept;
469 std::string
showAddr (
void const* addr) noexcept;
485 : BOTTOM_INDICATOR +
" «" + typeStr(ptr) +
"»";
488 template<
typename SP>
490 showSmartPtr (SP
const& smPtr, std::string label =
"smP")
492 using TargetType =
typename SP::element_type;
495 : BOTTOM_INDICATOR +
" «" + typeStr(smPtr) +
"»";
506 operator""_KiB (
unsigned long long const siz)
508 return uint(siz) * 1024u;
512 operator""_MiB (
unsigned long long const siz)
514 return uint(siz) * 1024u*1024u;
517 inline unsigned long long 518 operator""_GiB (
unsigned long long const siz)
520 return siz * 1024uLL*1024uLL*1024uLL;
inline string literal This is a marker type to indicate that
Implementation namespace for support and library code.
failsafe invocation of custom string conversion.