diff --git a/cmake_config.h.in b/cmake_config.h.in index 64db4ade9e..fdf9aa4e34 100644 --- a/cmake_config.h.in +++ b/cmake_config.h.in @@ -98,12 +98,14 @@ #define INCLUDE_FMT_RANGES #define INCLUDE_FMT_OSTREAM - #define VT_FMT_NAMESPACE namespace fmt + #define VT_FMT_NAMESPACE_BEGIN namespace fmt { + #define VT_FMT_NAMESPACE_END } #else #define INCLUDE_FMT_CORE #define INCLUDE_FMT_FORMAT #define INCLUDE_FMT_RANGES #define INCLUDE_FMT_OSTREAM - #define VT_FMT_NAMESPACE namespace fmt::vt + #define VT_FMT_NAMESPACE_BEGIN namespace fmt { inline namespace vt { + #define VT_FMT_NAMESPACE_END } } #endif diff --git a/src/vt/elm/elm_id.h b/src/vt/elm/elm_id.h index cb392d7d79..634b7d7556 100644 --- a/src/vt/elm/elm_id.h +++ b/src/vt/elm/elm_id.h @@ -97,7 +97,7 @@ struct hash { #include "vt/cmake_config.h" #include INCLUDE_FMT_FORMAT -namespace fmt { +VT_FMT_NAMESPACE_BEGIN /// Custom fmt formatter/print for \c vt::elm::ElementIDStruct template <> @@ -138,6 +138,6 @@ struct formatter<::vt::elm::ElementIDStruct> { } }; -} /* end namespace fmt */ +VT_FMT_NAMESPACE_END #endif /*INCLUDED_VT_ELM_ELM_ID_H*/ diff --git a/src/vt/epoch/epoch_type.h b/src/vt/epoch/epoch_type.h index 93c808f2f0..b2ddf46a5b 100644 --- a/src/vt/epoch/epoch_type.h +++ b/src/vt/epoch/epoch_type.h @@ -111,7 +111,7 @@ struct hash { #include "vt/cmake_config.h" #include INCLUDE_FMT_FORMAT -namespace fmt { +VT_FMT_NAMESPACE_BEGIN /// Custom fmt formatter/print for \c EpochType template <> @@ -151,7 +151,7 @@ struct formatter<::vt::epoch::EpochType> { } }; -} /* end namespace fmt */ +VT_FMT_NAMESPACE_END namespace vt { diff --git a/src/vt/rdma/rdma_common.h b/src/vt/rdma/rdma_common.h index f206eac03a..daad768493 100644 --- a/src/vt/rdma/rdma_common.h +++ b/src/vt/rdma/rdma_common.h @@ -117,30 +117,35 @@ static constexpr ByteType rdma_default_byte_size = sizeof(char); }} //end namespace vt::rdma -VT_FMT_NAMESPACE { - template <> - struct formatter<::vt::rdma::Type> : formatter { - template - auto format(::vt::rdma::Type t, FormatContext& ctx) { - std::string_view name = "Unknown"; - switch (t) { - case ::vt::rdma::Type::Get: - name = "Get"; - break; - case ::vt::rdma::Type::Put: - name = "Put"; - break; - case ::vt::rdma::Type::GetOrPut: - name = "GetOrPut"; - break; - case ::vt::rdma::Type::Uninitialized: - name = "Uninitialized"; - break; - } - return formatter::format(name, ctx); +VT_FMT_NAMESPACE_BEGIN + +template <> +struct formatter<::vt::rdma::Type> : formatter { + template + auto format(::vt::rdma::Type t, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (t) { + case ::vt::rdma::Type::Get: + name = "Get"; + break; + case ::vt::rdma::Type::Put: + name = "Put"; + break; + case ::vt::rdma::Type::GetOrPut: + name = "GetOrPut"; + break; + case ::vt::rdma::Type::Uninitialized: + name = "Uninitialized"; + break; + default: + name = fmt::format( + "{}", static_cast>(t)); } - }; -} // VT_FMT_NAMESPACE + return formatter::format(name, ctx); + } +}; + +VT_FMT_NAMESPACE_END #define PRINT_CHANNEL_TYPE(rdma_op_type) ( \ rdma_op_type == vt::rdma::Type::Get ? "rdma::Get" : ( \ diff --git a/src/vt/termination/interval/interval.h b/src/vt/termination/interval/interval.h index 99da07d776..06a5e03903 100644 --- a/src/vt/termination/interval/interval.h +++ b/src/vt/termination/interval/interval.h @@ -237,18 +237,20 @@ struct Interval; }}} -VT_FMT_NAMESPACE { - template - struct formatter<::vt::term::interval::Interval> - : formatter { - template - auto format( - const ::vt::term::interval::Interval& interval, - FormatContext& ctx) { - return format_to( - ctx.out(), "Interval[{}, {}]", interval.lower(), interval.upper()); - } - }; -} // VT_FMT_NAMESPACE +VT_FMT_NAMESPACE_BEGIN + +template +struct formatter<::vt::term::interval::Interval> + : formatter { + template + auto format( + const ::vt::term::interval::Interval& interval, + FormatContext& ctx) { + return format_to( + ctx.out(), "Interval[{}, {}]", interval.lower(), interval.upper()); + } +}; + +VT_FMT_NAMESPACE_END #endif /*INCLUDED_VT_TERMINATION_INTERVAL_INTERVAL_H*/ diff --git a/src/vt/timing/timing.h b/src/vt/timing/timing.h index e2495751f4..228b0e1cdf 100644 --- a/src/vt/timing/timing.h +++ b/src/vt/timing/timing.h @@ -63,13 +63,7 @@ TimeType getCurrentTime(); }} /* end namespace vt::timing */ -VT_FMT_NAMESPACE { - template <> - struct formatter<::vt::TimeTypeWrapper> { - template - constexpr auto parse(ParseContext& ctx) { - return ctx.begin(); - } +VT_FMT_NAMESPACE_BEGIN template auto format(::vt::TimeTypeWrapper const& t, FormatContext& ctx) { @@ -80,6 +74,14 @@ VT_FMT_NAMESPACE { } }; -} // VT_FMT_NAMESPACE + template + auto format(::vt::TimeTypeWrapper const& t, FormatContext& ctx) { + return fmt::format_to( + ctx.out(), "{}", + to_engineering_string(t.seconds(), 3, eng_exponential, "s")); + } +}; + +VT_FMT_NAMESPACE_END #endif /*INCLUDED_VT_TIMING_TIMING_H*/ diff --git a/src/vt/topos/index/dense/dense_array.h b/src/vt/topos/index/dense/dense_array.h index 9a57c856e0..81b0f9fac8 100644 --- a/src/vt/topos/index/dense/dense_array.h +++ b/src/vt/topos/index/dense/dense_array.h @@ -159,18 +159,20 @@ static_assert( }} // end namespace vt::index -VT_FMT_NAMESPACE { - template - struct formatter<::vt::index::DenseIndexArray> - : formatter> { - template - auto format( - const ::vt::index::DenseIndexArray& wrapper, - FormatContext& ctx) { - return formatter>::format(wrapper.dims, ctx); - } - }; -} // VT_FMT_NAMESPACE +VT_FMT_NAMESPACE_BEGIN + +template +struct formatter<::vt::index::DenseIndexArray> + : formatter> { + template + auto format( + const ::vt::index::DenseIndexArray& wrapper, + FormatContext& ctx) { + return formatter>::format(wrapper.dims, ctx); + } +}; + +VT_FMT_NAMESPACE_END #include "vt/topos/index/dense/dense_array.impl.h" diff --git a/src/vt/vrt/collection/balance/greedylb/greedylb.h b/src/vt/vrt/collection/balance/greedylb/greedylb.h index 27177a6558..fe5c63d756 100644 --- a/src/vt/vrt/collection/balance/greedylb/greedylb.h +++ b/src/vt/vrt/collection/balance/greedylb/greedylb.h @@ -41,6 +41,7 @@ //@HEADER */ +#include #if !defined INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H #define INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H @@ -126,29 +127,36 @@ struct GreedyLB : LoadSamplerBaseLB { }}}} /* end namespace vt::vrt::collection::lb */ -VT_FMT_NAMESPACE { - template <> - struct formatter<::vt::vrt::collection::lb::DataDistStrategy> - : formatter { - template - auto - format(::vt::vrt::collection::lb::DataDistStrategy c, FormatContext& ctx) { - std::string_view name = "Unknown"; - switch (c) { - case ::vt::vrt::collection::lb::DataDistStrategy::scatter: - name = "scatter"; - break; - case ::vt::vrt::collection::lb::DataDistStrategy::bcast: - name = "bcast"; - break; - case ::vt::vrt::collection::lb::DataDistStrategy::pt2pt: - name = "pt2pt"; - break; - } - return formatter::format(name, ctx); +VT_FMT_NAMESPACE_BEGIN + +template <> +struct formatter<::vt::vrt::collection::lb::DataDistStrategy> + : formatter { + template + auto + format(::vt::vrt::collection::lb::DataDistStrategy c, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (c) { + case ::vt::vrt::collection::lb::DataDistStrategy::scatter: + name = "scatter"; + break; + case ::vt::vrt::collection::lb::DataDistStrategy::bcast: + name = "bcast"; + break; + case ::vt::vrt::collection::lb::DataDistStrategy::pt2pt: + name = "pt2pt"; + break; + default: + name = fmt::format( + "{}", + static_cast< + std::underlying_type_t<::vt::vrt::collection::lb::DataDistStrategy>>( + c)); } - }; + return formatter::format(name, ctx); + } +}; -} // VT_FMT_NAMESPACE +VT_FMT_NAMESPACE_END #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H*/ diff --git a/src/vt/vrt/collection/balance/lb_args_enum_converter.h b/src/vt/vrt/collection/balance/lb_args_enum_converter.h index 050adfeb86..fa2dce3ccb 100644 --- a/src/vt/vrt/collection/balance/lb_args_enum_converter.h +++ b/src/vt/vrt/collection/balance/lb_args_enum_converter.h @@ -100,7 +100,7 @@ struct LBArgsEnumConverter { auto err = fmt::format( "LBArgsEnumConverter: enum '{}' value '{}' corresponding to LB " "argument '{}' does not have a string associated with it", - enum_type_, e, par_name_ + enum_type_, static_cast>(e), par_name_ ); vtAbort(err); } diff --git a/src/vt/vrt/collection/balance/temperedlb/criterion.h b/src/vt/vrt/collection/balance/temperedlb/criterion.h index 5f1e278771..4f3c9186d9 100644 --- a/src/vt/vrt/collection/balance/temperedlb/criterion.h +++ b/src/vt/vrt/collection/balance/temperedlb/criterion.h @@ -93,26 +93,26 @@ struct Criterion { }}}} /* end namespace vt::vrt::collection::lb */ -VT_FMT_NAMESPACE { - template <> - struct formatter<::vt::vrt::collection::lb::CriterionEnum> - : formatter { - template - auto - format(::vt::vrt::collection::lb::CriterionEnum c, FormatContext& ctx) { - std::string_view name = "Unknown"; - switch (c) { - case ::vt::vrt::collection::lb::CriterionEnum::Grapevine: - name = "Grapevine"; - break; - case ::vt::vrt::collection::lb::CriterionEnum::ModifiedGrapevine: - name = "ModifiedGrapevine"; - break; - } - return formatter::format(name, ctx); +VT_FMT_NAMESPACE_BEGIN + +template <> +struct formatter<::vt::vrt::collection::lb::CriterionEnum> + : formatter { + template + auto format(::vt::vrt::collection::lb::CriterionEnum c, FormatContext& ctx) { + std::string_view name = "Unknown"; + switch (c) { + case ::vt::vrt::collection::lb::CriterionEnum::Grapevine: + name = "Grapevine"; + break; + case ::vt::vrt::collection::lb::CriterionEnum::ModifiedGrapevine: + name = "ModifiedGrapevine"; + break; } - }; + return formatter::format(name, ctx); + } +}; -} // VT_FMT_NAMESPACE +VT_FMT_NAMESPACE_END #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_CRITERION_H*/ diff --git a/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h b/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h index 8c2ca050c7..b56414a333 100644 --- a/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h +++ b/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h @@ -167,103 +167,4 @@ enum struct KnowledgeEnum : uint8_t { }}}} /* end namespace vt::vrt::collection::lb */ -VT_FMT_NAMESPACE { - // Specialize fmt::formatter for ObjectOrderEnum - template <> - struct formatter<::vt::vrt::collection::lb::ObjectOrderEnum> - : formatter { - template - auto - format(::vt::vrt::collection::lb::ObjectOrderEnum c, FormatContext& ctx) { - std::string_view name = "Unknown"; - switch (c) { - case ::vt::vrt::collection::lb::ObjectOrderEnum::Arbitrary: - name = "Arbitrary"; - break; - case ::vt::vrt::collection::lb::ObjectOrderEnum::ElmID: - name = "ElmID"; - break; - case ::vt::vrt::collection::lb::ObjectOrderEnum::FewestMigrations: - name = "FewestMigrations"; - break; - case ::vt::vrt::collection::lb::ObjectOrderEnum::SmallObjects: - name = "SmallObjects"; - break; - case ::vt::vrt::collection::lb::ObjectOrderEnum::LargestObjects: - name = "LargestObjects"; - break; - } - return formatter::format(name, ctx); - } - }; - - // Specialize fmt::formatter for CMFTypeEnum - template <> - struct formatter<::vt::vrt::collection::lb::CMFTypeEnum> - : formatter { - template - auto format(::vt::vrt::collection::lb::CMFTypeEnum c, FormatContext& ctx) { - std::string_view name = "Unknown"; - switch (c) { - case ::vt::vrt::collection::lb::CMFTypeEnum::Original: - name = "Original"; - break; - case ::vt::vrt::collection::lb::CMFTypeEnum::NormByMax: - name = "NormByMax"; - break; - case ::vt::vrt::collection::lb::CMFTypeEnum::NormBySelf: - name = "NormBySelf"; - break; - case ::vt::vrt::collection::lb::CMFTypeEnum::NormByMaxExcludeIneligible: - name = "NormByMaxExcludeIneligible"; - break; - } - return formatter::format(name, ctx); - } - }; - - // Specialize fmt::formatter for KnowledgeEnum - template <> - struct formatter<::vt::vrt::collection::lb::KnowledgeEnum> - : formatter { - template - auto - format(::vt::vrt::collection::lb::KnowledgeEnum c, FormatContext& ctx) { - std::string_view name = "Unknown"; - switch (c) { - case ::vt::vrt::collection::lb::KnowledgeEnum::UserDefined: - name = "UserDefined"; - break; - case ::vt::vrt::collection::lb::KnowledgeEnum::Complete: - name = "Complete"; - break; - case ::vt::vrt::collection::lb::KnowledgeEnum::Log: - name = "Log"; - break; - } - return formatter::format(name, ctx); - } - }; - - // Specialize fmt::formatter for KnowledgeEnum - template <> - struct formatter<::vt::vrt::collection::lb::InformTypeEnum> - : formatter { - template - auto - format(::vt::vrt::collection::lb::InformTypeEnum c, FormatContext& ctx) { - std::string_view name = "Unknown"; - switch (c) { - case ::vt::vrt::collection::lb::InformTypeEnum::SyncInform: - name = "SyncInform"; - break; - case ::vt::vrt::collection::lb::InformTypeEnum::AsyncInform: - name = "AsyncInform"; - break; - } - return formatter::format(name, ctx); - } - }; -} // VT_FMT_NAMESPACE - #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_TEMPERED_ENUMS_H*/ diff --git a/tests/unit/lb/test_lbargs_enum_conv.nompi.cc b/tests/unit/lb/test_lbargs_enum_conv.nompi.cc index c5658660d2..f6775cde10 100644 --- a/tests/unit/lb/test_lbargs_enum_conv.nompi.cc +++ b/tests/unit/lb/test_lbargs_enum_conv.nompi.cc @@ -148,7 +148,7 @@ TEST_F(TestLBArgsEnumConverter, test_enum_converter_config) { }}} // end namespace vt::tests::unit -VT_FMT_NAMESPACE { +VT_FMT_NAMESPACE_BEGIN template <> struct formatter<::vt::tests::unit::DummyEnum> : formatter { template @@ -168,4 +168,4 @@ VT_FMT_NAMESPACE { return formatter::format(name, ctx); } }; -} // VT_FMT_NAMESPACE +VT_FMT_NAMESPACE_END