xtd 0.2.0
register_any_stringer.hpp
Go to the documentation of this file.
1
3#pragma once
6
8extern std::unordered_map<std::type_index, std::function<std::string(std::any const&)>> __any_stringer__;
9
10template<class type_t, class function_t>
11inline std::pair<const std::type_index, std::function<std::string(std::any const&)>> __to_any_stringer__(function_t const& func) {
12 return {
13 std::type_index(typeid(type_t)),
14 [f = func](std::any const & value)->std::string {
15 if constexpr(std::is_void_v<type_t>) return f();
16 else return f(std::any_cast<const type_t&>(value));
17 }
18 };
19}
21
23namespace xtd {
25
37 template<class type_t, class function_t>
38 inline void register_any_stringer(const function_t& func) {
39 unregister_any_stringer<type_t>();
40 __any_stringer__.insert(__to_any_stringer__<type_t>(func));
41 }
43}
xtd::delegate< result_t(arguments_t... arguments)> func
Represents a delegate that has variables parameters and returns a value of the type specified by the ...
Definition func.hpp:27
void register_any_stringer(const function_t &func)
Register an any stringer method for a specified type.
Definition register_any_stringer.hpp:38
@ f
The F key.
Contains xtd::collections::generic::key_value_pair <key_t, value_t> struct.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::register_any_stringer and xtd::unregister_any_stringer method.