28 #ifndef LIB_META_UTIL_H 29 #define LIB_META_UTIL_H 31 #include "lib/integral.hpp" 42 template <
typename T,
typename D>
57 template <
bool B,
class T =
void>
82 template <
class Cond,
class T =
void>
83 using enable_if =
typename enable_if_c<Cond::value, T>::type;
85 template <
class Cond,
class T =
void>
86 using disable_if =
typename enable_if_c<not Cond::value, T>::type;
96 struct No_t {
char more_than_one[4]; };
109 template<
typename TY>
113 static Yes_t check(
typename ZZ::type *);
115 static Yes_t check(
typename X::Type *);
117 static No_t check(...);
120 static const bool value = (
sizeof(Yes_t)==
sizeof(check<TY>(0)));
126 struct has_TypeResult : std::bool_constant<_DetectNested_TypeResult<X>::value> { };
131 template<
typename...>
136 template<
typename X,
typename...XS>
143 template<
typename...XS>
149 template<
class SELF,
typename ...ARGS>
166 static Yes_t check_implicit(std::string);
167 static Yes_t check_implicit(std::string_view);
168 static Yes_t check_implicit(
const char*);
169 static No_t check_implicit(...);
172 template<
class XX,
int i = sizeof(&XX::operator std::
string)>
177 static Yes_t check_explicit(
Probe<XX> * );
179 static No_t check_explicit(...);
182 static const bool value = (
sizeof(Yes_t)==
sizeof(check_implicit (std::declval<X>())))
183 or (
sizeof(Yes_t)==
sizeof(check_explicit<X>(0)));
198 template<
typename TY>
202 static Yes_t check(
typename X::List *);
204 static No_t check(...);
207 static const bool value = (
sizeof(Yes_t)==
sizeof(check<TY>(0)));
214 template<
typename FUN>
217 template<
typename FF,
218 typename SEL = decltype(&FF::operator())>
225 static No_t check(...);
228 static const bool value = (
sizeof(Yes_t)==
sizeof(check<FUN>(0)));
238 template<
class BAS,
size_t m=0>
286 extern const std::string FUNCTION_INDICATOR;
287 extern const std::string FAILURE_INDICATOR;
288 extern const std::string BOTTOM_INDICATOR;
289 extern const std::string VOID_INDICATOR;
291 extern const std::string BOOL_FALSE_STR;
292 extern const std::string BOOL_TRUE_STR;
314 template<
typename TY>
318 auto mangledType = obj?
typeid(*obj).name()
320 return humanReadableTypeID (mangledType);
323 {
return FAILURE_INDICATOR; }
325 template<
typename TY>
326 inline disable_if<std::is_pointer<TY>,
328 typeStr (TY
const& ref) noexcept
336 return VOID_INDICATOR;
346 template<
typename TY>
348 typeSymbol (TY
const* obj =
nullptr)
350 auto mangledType = obj?
typeid(*obj).name()
352 return primaryTypeComponent (mangledType);
355 template<
typename TY>
356 inline disable_if<std::is_pointer<TY>,
358 typeSymbol (TY
const& ref)
360 return typeSymbol (&ref);
370 using lib::meta::typeStr;
371 using lib::meta::FAILURE_INDICATOR;
372 using lib::meta::BOTTOM_INDICATOR;
389 template<
typename X,
typename COND =
void>
393 invoke (X
const& x) noexcept
394 try {
return "«"+typeStr(x)+
"»"; }
395 catch(...) {
return FAILURE_INDICATOR; }
402 invoke (X
const& val) noexcept
403 try {
return std::string(val); }
404 catch(...) {
return FAILURE_INDICATOR; }
413 struct StringConv<X*, lib::meta::disable_if<std::__or_<std::is_same<std::remove_cv_t<X>,
char>
414 ,std::is_same<std::remove_cv_t<X>,
void>
418 invoke (X
const* ptr) noexcept
420 : BOTTOM_INDICATOR +
"«"+typeStr(ptr)+
"»";
422 catch(...) {
return FAILURE_INDICATOR; }
437 return yes? lib::meta::BOOL_TRUE_STR
438 : lib::meta::BOOL_FALSE_STR;
443 std::string showFloat (
float) noexcept;
455 std::string showSize (
size_t) noexcept;
460 std::string
showAdr (
void const* addr) noexcept;
463 inline lib::meta::disable_if<std::is_pointer<X>,
477 : BOTTOM_INDICATOR +
" «" + typeStr(ptr) +
"»";
480 template<
typename SP>
482 showSmartPtr (SP
const& smPtr, std::string label =
"smP")
484 using TargetType =
typename SP::element_type;
487 : BOTTOM_INDICATOR +
" «" + typeStr(smPtr) +
"»";
498 operator""_KiB (ullong
const siz)
500 return uint(siz) * 1024u;
504 operator""_MiB (ullong
const siz)
506 return uint(siz) * 1024u*1024u;
510 operator""_GiB (ullong
const siz)
512 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.