xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
any.h
Go to the documentation of this file.
1 #pragma once
4 #include <any>
5 #include <functional>
6 #include <string>
7 #include <typeindex>
8 #include <typeinfo>
9 #include <type_traits>
10 #include <unordered_map>
11 #include <vector>
12 
14 extern std::unordered_map<std::type_index, std::function<std::string(std::any const&)>> __any_stringer__;
15 
16 template<class type_t, class function_t>
17 inline std::pair<const std::type_index, std::function<std::string(std::any const&)>> __to_any_stringer__(function_t const &func) {
18  return {
19  std::type_index(typeid(type_t)),
20  [f = func](std::any const &value)->std::string {
21  if constexpr (std::is_void_v<type_t>) return f();
22  else return f(std::any_cast<const type_t&>(value));
23  }
24  };
25 }
27 
29 namespace xtd {
40  template<class type_t, class function_t>
41  inline void register_any_stringer(const function_t& func) {
42  __any_stringer__.insert(__to_any_stringer__<type_t>(func));
43  }
44 }
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Definition: delegate.h:236
void register_any_stringer(const function_t &func)
Register an any stringer method for a specified type.
Definition: any.h:41
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:17
@ f
The F key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17