55#if !defined(SFINAE_WARNING)
57# define SFINAE_WARNING(TYPE) \
58 if(::tim::trait::is_available<TYPE>::value) \
60 static bool _once = false; \
64 fprintf(stderr, "[%s@%s:%i]> Warning! SFINAE disabled for %s\n", \
65 __FUNCTION__, __FILE__, __LINE__, \
66 ::tim::demangle<TYPE>().c_str()); \
70# define SFINAE_WARNING(...)
101 template <
typename T>
103 std::true_type) TIMEMORY_VISIBILITY(
"default");
105 template <
typename T>
107 std::false_type) TIMEMORY_VISIBILITY(
"default");
109 template <
typename T>
112 template <
size_t Idx, enable_if_t<Idx != TIMEMORY_COMPONENTS_END> = 0>
115 template <
size_t Idx, enable_if_t<Idx == TIMEMORY_COMPONENTS_END> = 0>
116 static auto get() TIMEMORY_VISIBILITY(
"default");
118 template <
typename... Tp,
enable_if_t<
sizeof...(Tp) != 1> = 0>
119 static auto get() TIMEMORY_VISIBILITY(
"default");
121 template <
size_t... Idx,
enable_if_t<
sizeof...(Idx) != 1> = 0>
122 static auto get() TIMEMORY_VISIBILITY(
"default");
124 template <
size_t... Idx>
125 static auto get(std::index_sequence<Idx...>) TIMEMORY_VISIBILITY(
"default");
139template <
size_t Idx, enable_if_t<Idx == TIMEMORY_COMPONENTS_END>>
143 return get(std::make_index_sequence<Idx>{});
148template <
typename... Tp,
enable_if_t<
sizeof...(Tp) != 1>>
157template <
size_t... Idx,
enable_if_t<
sizeof...(Idx) != 1>>
166template <
size_t... Idx>
202 template <
typename Head,
typename... Tail>
205 return !std::is_same<decay_t<Head>,
std::string>::value;
208 template <
typename Head,
typename... Tail>
214 template <
typename Head,
typename... Tail>
217 return std::is_same<decay_t<Head>,
std::string>::value;
220 template <
typename Head,
typename... Tail>
227 template <
typename Tp>
230 return get_distance_sfinae(_data);
234 template <
typename Tp>
235 static auto get_distance_sfinae(
const Tp& _data,
int)
236 ->
decltype(std::distance(_data.begin(), _data.end()), size_t())
238 return std::distance(_data.begin(), _data.end());
241 template <
typename Tp>
242 static auto get_distance_sfinae(
const Tp&,
long) ->
size_t
247 template <
typename Tp>
248 static auto get_distance_sfinae(
const Tp& _data)
249 ->
decltype(get_distance_sfinae(_data, 0))
251 return get_distance_sfinae(_data, 0);
255 template <typename Tp, enable_if_t<std::is_arithmetic<Tp>::value,
int> = 0>
261 template <typename Tp, enable_if_t<!std::is_arithmetic<Tp>::value,
int> = 0>
263 ->
decltype(get_entry_sfinae_(_data, _idx))
265 return get_entry_sfinae_<Tp>(_data, _idx);
268 template <
typename Tp,
size_t Idx>
275 template <
typename Tp>
276 static auto get_entry_sfinae(
const Tp& _data,
int,
size_t _idx)
277 ->
decltype(_data.begin(),
typename Tp::value_type())
279 auto sz = std::distance(_data.begin(), _data.end());
281 auto itr = _data.begin();
282 std::advance(itr, n);
286 template <
typename Tp>
287 static Tp get_entry_sfinae(
const Tp& _data,
long,
size_t)
292 template <
typename Tp>
293 static auto get_entry_sfinae_(
const Tp& _data,
size_t _idx)
294 ->
decltype(get_entry_sfinae(_data, 0, _idx))
296 return get_entry_sfinae<Tp>(_data, 0, _idx);
300 template <
typename Tp,
typename Wp,
typename Pp>
301 static void write(std::vector<std::stringstream*>& _os,
302 std::ios_base::fmtflags _format,
const Tp& _data,
const Wp& _width,
307 for(
size_t i = 0; i < num_data; ++i)
309 auto _idata = get_entry<Tp>(_data, i);
310 auto _iwidth = get_entry<Wp>(_width, i);
311 auto _iprec = get_entry<Pp>(_prec, i);
312 auto* ss =
new std::stringstream;
314 (*ss) << std::setw(_iwidth) << std::setprecision(_iprec) << _idata;
315 _os.emplace_back(ss);
319 template <
typename... Tp,
size_t... Idx,
typename Wp,
typename Pp>
320 static void write(std::vector<std::stringstream*>& _os,
321 std::ios_base::fmtflags _format,
const std::tuple<Tp...>& _data,
325 write(_os, _format, std::get<Idx>(_data), _width, _prec));
328 template <
typename... Tp,
typename Wp,
typename Pp>
329 static void write(std::vector<std::stringstream*>& _os,
330 std::ios_base::fmtflags _format,
const std::tuple<Tp...>& _data,
331 const Wp& _width,
const Pp& _prec)
333 constexpr size_t N =
sizeof...(Tp);
338 template <
typename Tp>
341 return get_labels_size_sfinae(_data, 0);
345 template <
typename Tp>
346 static auto get_labels_size_sfinae(
const Tp& _data,
int)
347 ->
decltype((void) _data.label_array(), int64_t())
349 return _data.label_array().size();
352 template <
typename Tp>
353 static auto get_labels_size_sfinae(
const Tp&,
long) -> int64_t
359 template <
typename Tp>
362 return get_labels_sfinae(_data, 0, 0);
366 template <
typename Tp>
367 static auto get_labels_sfinae(
const Tp& _data,
int,
int)
368 ->
decltype((void) _data.label_array(),
strvec_t{})
371 for(
const auto& itr : _data.label_array())
376 template <
typename Tp>
377 static auto get_labels_sfinae(
const Tp& _data,
int,
long)
378 ->
decltype((void) _data.get_label(),
strvec_t{})
380 return strvec_t{ _data.get_label() };
383 template <
typename Tp>
384 static auto get_labels_sfinae(
const Tp&,
long,
long) ->
strvec_t
390 template <
typename T>
396 template <
typename Tp>
399 std::stringstream ss;
404 template <
typename... T,
size_t... Idx>
407 using init_list_type = std::initializer_list<std::string>;
408 auto&& ret = init_list_type{ (
as_string(std::get<Idx>(_obj)))... };
412 template <
typename... T>
415 constexpr size_t N =
sizeof...(T);
420 template <
typename Tp>
423 return get_display_units_sfinae(_data, 0, 0);
427 template <
typename Tp>
428 static auto get_display_units_sfinae(
const Tp& _data,
int,
int)
429 ->
decltype((void) _data.display_unit_array(),
strvec_t{})
432 for(
const auto& itr : _data.display_unit_array())
437 template <
typename Tp>
438 static auto get_display_units_sfinae(
const Tp& _data,
int,
long)
439 ->
decltype((void) _data.get_display_unit(),
strvec_t{})
445 template <
typename Tp>
446 static auto get_display_units_sfinae(
const Tp&,
long,
long) ->
strvec_t
454 template <
typename Tp>
457 return get_widths_sfinae(_data, 0);
461 template <
typename Tp>
462 static auto get_widths_sfinae(
const Tp& _data,
int)
465 return _data.width_array();
468 template <
typename Tp>
469 static auto get_widths_sfinae(
const Tp&,
long) ->
sizevector_t
488 for(
const auto& itr : values)
490 while(item.find(itr) != string_t::npos)
491 item = item.replace(item.find(itr), itr.length(), str);
501 for(
auto& itr : _str)
511 for(
auto& itr : _str)
522 return std::any_of(items.begin(), items.end(), [&lstr](
const auto& itr) {
523 return lstr.find(itr) != string_t::npos;
530 template <
typename Tp,
typename... Args>
534 std::forward<Args>(
_args)...);
543 template <
typename Tp,
typename... _Extra>
544 static bool is_empty(
const std::vector<Tp, _Extra...>& obj)
546 for(
const auto& itr : obj)
556 template <
template <
typename...>
class Tuple,
typename... Tp>
560 constexpr size_t N =
sizeof...(Tp);
561 std::bitset<N> _bits;
570 template <
bool EnabledV,
typename Arg, enable_if_t<EnabledV,
int> = 0>
579 template <
bool EnabledV,
typename Arg, enable_if_t<!EnabledV,
int> = 0>
586template <
typename Tp>
593 using get_type = std::tuple<pointer_t, bool, bool, bool>;
595 template <
typename Up = Tp>
598 template <
typename Up = Tp>
602 template <
typename U = Tp,
typename V =
typename U::value_type>
605 template <
typename U = Tp,
typename V =
typename U::value_type>
607 !std::is_same<
typename U::storage_type,
611 template <
typename U = Tp,
typename V =
typename U::value_type>
613 std::is_same<
typename U::storage_type,
622template <
typename Tp>
629 template <
typename Up = Tp>
630 TIMEMORY_INLINE
void sfinae(
633 template <
typename Up = Tp>
634 TIMEMORY_INLINE
void sfinae(
638 template <
typename StorageT>
639 TIMEMORY_INLINE
auto sfinae(StorageT* ptr,
int)
const
640 ->
decltype(ptr->finalize(), void())
645 template <
typename StorageT>
646 TIMEMORY_INLINE
void sfinae(StorageT*,
long)
const
std::tuple_element< N, std::tuple< Types... > >::type & get(tim::auto_bundle< Tag, Types... > &obj)
const hash_alias_ptr_t hash_value_t std::string *& _ret
std::array< bool, scope_count > input_type
typename is_available< T >::type is_available_t
std::make_integer_sequence< size_t, Num > make_index_sequence
Alias template make_index_sequence.
std::array< char *, 4 > _args
impl::index_of< Tp, Type > index_of
typename std::enable_if< B, T >::type enable_if_t
Alias template for enable_if.
tim::mpl::apply< std::string > string
const std::string std::ostream * os
std::integer_sequence< size_t, Idx... > index_sequence
Alias template index_sequence.
Include the macros for operations.
Declare the operations types.
A very lightweight storage class which provides nothing.
static string_t join(SepT &&separator, Tuple &&__tup, index_sequence< Idx... >) noexcept
common string manipulation utilities
static Tp get_entry(const Tp &_data, size_t)
static constexpr bool not_string(enable_if_t< sizeof...(Tail) !=0, int >=0)
static string_t uppercase(string_t _str)
convert to uppercase
static constexpr bool is_string(enable_if_t< sizeof...(Tail)==0, int >=0)
static strvec_t get_labels(const Tp &_data)
static strvec_t as_string_vec(const std::tuple< T... > &_obj, index_sequence< Idx... >)
static void print_tag(std::ostream &os, const Arg &_arg)
static strvec_t as_string_vec(const std::tuple< T... > &_obj)
std::vector< string_t > strvec_t
static strvec_t get_display_units(const Tp &_data)
static void write(std::vector< std::stringstream * > &_os, std::ios_base::fmtflags _format, const std::tuple< Tp... > &_data, const Wp &_width, const Pp &_prec, index_sequence< Idx... >)
std::set< string_t > strset_t
static int64_t get_labels_size(const Tp &_data)
static string_t attribute_string(const string_t &key, const string_t &item)
generate an attribute
static void print_tag(std::ostream &, const Arg &)
static sizevector_t get_widths(const Tp &_data)
static bool is_empty(const std::vector< Tp, _Extra... > &obj)
static void write(std::vector< std::stringstream * > &_os, std::ios_base::fmtflags _format, const Tp &_data, const Wp &_width, const Pp &_prec)
static std::string as_string(const Tp &_obj)
std::stringstream stringstream_t
static void write(std::vector< std::stringstream * > &_os, std::ios_base::fmtflags _format, const std::tuple< Tp... > &_data, const Wp &_width, const Pp &_prec)
std::vector< size_t > sizevector_t
static bool is_empty(const Tuple< Tp... > &obj)
static string_t join(Tp &&_delim, Args &&... _args)
shorthand for apply<string_t>::join(...)
static bool is_empty(const std::string &obj)
static auto get_entry(const Tp &_data, size_t _idx) -> decltype(get_entry_sfinae_(_data, _idx))
static string_t lowercase(string_t _str)
convert to lowercase
std::map< string_t, string_t > attributes_t
static constexpr bool is_string(enable_if_t< sizeof...(Tail) !=0, int >=0)
static size_t get_distance(const Tp &_data)
static constexpr bool not_string(enable_if_t< sizeof...(Tail)==0, int >=0)
static strvec_t as_string_vec(const T &_data)
static bool contains(const string_t &str, const strset_t &items)
check if str contains any of the string items
static string_t replace(string_t &item, const string_t &str, const strset_t &values)
replace matching values in item with str
static get_type get(enable_if_t< trait::uses_value_storage< U, V >::value, int >=0)
std::tuple< pointer_t, bool, bool, bool > get_type
init_storage(enable_if_t<!trait::uses_value_storage< Up >::value, int >=0)
static get_type get(enable_if_t<!trait::uses_value_storage< U, V >::value &&std::is_same< typename U::storage_type, component::empty_storage >::value, int >=0)
init_storage(enable_if_t< trait::uses_value_storage< Up >::value, int >=0)
static get_type get(enable_if_t<!trait::uses_value_storage< U, V >::value &&!std::is_same< typename U::storage_type, component::empty_storage >::value, int >=0)
This provides an object that can initialize the storage opaquely, e.g.
static storage_initializer get()
trait that signifies that an implementation for the component is available. When this is set to false...
This trait is used to determine whether the (expensive) instantiation of the storage class happens.
#define TIMEMORY_FOLD_EXPRESSION(...)
#define TIMEMORY_RETURN_FOLD_EXPRESSION(...)