mmCEsim 0.3.0
mmWave Channel Estimation Simulation
fmt.h
Go to the documentation of this file.
1
14#ifndef _FMT_H_
15#define _FMT_H_
16
17#include <any>
18#include <cassert>
19#include <fmt/core.h>
20#include <fmt/format.h>
21
22template <>
23struct fmt::formatter<std::any> {
24 template <typename ParseContext>
25 constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
26 // No format string is needed, so just return the end iterator.
27 return ctx.end();
28 }
29
30 template <typename FormatContext>
31 auto format(const std::any& value, FormatContext& ctx) -> decltype(ctx.out()) {
32 // Use std::any_cast to extract the value from the std::any object.
33 if (const auto* x = std::any_cast<const char>(&value)) return fmt::format_to(ctx.out(), "{}", *x);
34 else if (const auto* x = std::any_cast<const int>(&value)) return fmt::format_to(ctx.out(), "{}", *x);
35 else if (const auto* x = std::any_cast<const unsigned>(&value)) return fmt::format_to(ctx.out(), "{}", *x);
36 else if (const auto* x = std::any_cast<const size_t>(&value)) return fmt::format_to(ctx.out(), "{}", *x);
37 else if (const auto* x = std::any_cast<const std::string>(&value)) return fmt::format_to(ctx.out(), "{}", *x);
38 else if (const auto* x = std::any_cast<const double>(&value)) return fmt::format_to(ctx.out(), "{}", *x);
39 else {
40 assert(false && "Unknown type in std::any fmt!");
41 return fmt::format_to(ctx.out(), "<unknown type>");
42 }
43 }
44};
45
46#endif
auto format(const std::any &value, FormatContext &ctx) -> decltype(ctx.out())
Definition: fmt.h:31
constexpr auto parse(ParseContext &ctx) -> decltype(ctx.begin())
Definition: fmt.h:25