xtd 0.2.0
register_any_stringer.h
Go to the documentation of this file.
1 #pragma once
5 
7 extern std::unordered_map<std::type_index, std::function<std::string(std::any const&)>> __any_stringer__;
8 
9 template<class type_t, class function_t>
10 inline std::pair<const std::type_index, std::function<std::string(std::any const&)>> __to_any_stringer__(function_t const& func) {
11  return {
12  std::type_index(typeid(type_t)),
13  [f = func](std::any const & value)->std::string {
14  if constexpr(std::is_void_v<type_t>) return f();
15  else return f(std::any_cast<const type_t&>(value));
16  }
17  };
18 }
20 
22 namespace xtd {
33  template<class type_t, class function_t>
34  inline void register_any_stringer(const function_t& func) {
35  unregister_any_stringer<type_t>();
36  __any_stringer__.insert(__to_any_stringer__<type_t>(func));
37  }
38 }
void register_any_stringer(const function_t &func)
Register an any stringer method for a specified type.
Definition: register_any_stringer.h:34
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Contains xtd::register_any_stringer and xtd::unregister_any_stringer method.
delegate< result_t(arguments_t...)> func
Represents a delegate that has variables parameters and returns a value of the type specified by the ...
Definition: func.h:16