diff --git a/include/pmtv/format.hpp b/include/pmtv/format.hpp
index dd770d8..dc5dc3d 100644
--- a/include/pmtv/format.hpp
+++ b/include/pmtv/format.hpp
@@ -45,42 +45,23 @@ struct formatter
template
auto format(const P& value, FormatContext& ctx) const {
- // Using visit here is fairly slow. It is probably because of the recursive nature of it.
- // It is really simple to enumerate the possibilities here.
- using namespace pmtv;
- if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "null");
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "{}", std::get>(value));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "{}", std::get>(value));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>>(value), ", "));
- else if (std::holds_alternative>>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>>(value), ", "));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{}", std::get(value));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative>(value)) return fmt::format_to(ctx.out(), "[{}]", fmt::join(std::get>(value), ", "));
- else if (std::holds_alternative(value)) return fmt::format_to(ctx.out(), "{{{}}}", fmt::join(std::get(value), ", "));
- //static_assert(false);
- return fmt::format_to(ctx.out(), "error");
+ return std::visit([&ctx](const auto arg) {
+ using namespace pmtv;
+ using T = std::decay_t;
+ if constexpr (Scalar || Complex)
+ return fmt::format_to(ctx.out(), "{}", arg);
+ else if constexpr (std::same_as)
+ return fmt::format_to(ctx.out(), "{}", arg);
+ else if constexpr (UniformVector || UniformStringVector)
+ return fmt::format_to(ctx.out(), "[{}]", fmt::join(arg, ", "));
+ else if constexpr (std::same_as>) {
+ return fmt::format_to(ctx.out(), "[{}]", fmt::join(arg, ", "));
+ } else if constexpr (PmtMap) {
+ return fmt::format_to(ctx.out(), "{{{}}}", fmt::join(arg, ", "));
+ } else if constexpr (std::same_as)
+ return fmt::format_to(ctx.out(), "null");
+ return fmt::format_to(ctx.out(), "unknown type {}", typeid(T).name());
+ }, value);
}
};
diff --git a/meson.build b/meson.build
index 8b1d886..08bd4f2 100644
--- a/meson.build
+++ b/meson.build
@@ -2,7 +2,7 @@ project('pmt', 'cpp',
version : '0.0.2',
meson_version: '>=0.63.0',
license : 'GPLv3',
- default_options : ['cpp_std=c++20', 'warning_level=3'])
+ default_options : ['cpp_std=c++23', 'warning_level=3'])
cc = meson.get_compiler('cpp')
warnings_as_errors = get_option('warnings_as_errors') # Define this option in your meson_options.txt