Skip to content

Commit c980858

Browse files
JacobDomagalacwschilly
authored andcommitted
#2216: Fix namespace issues and remove uneeded custom formatters
1 parent 7ca1510 commit c980858

File tree

12 files changed

+127
-205
lines changed

12 files changed

+127
-205
lines changed

cmake_config.h.in

+4-2
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@
9898
#define INCLUDE_FMT_RANGES <fmt/ranges.h>
9999
#define INCLUDE_FMT_OSTREAM <fmt/ostream.h>
100100

101-
#define VT_FMT_NAMESPACE namespace fmt
101+
#define VT_FMT_NAMESPACE_BEGIN namespace fmt {
102+
#define VT_FMT_NAMESPACE_END }
102103
#else
103104
#define INCLUDE_FMT_CORE <fmt-vt/core.h>
104105
#define INCLUDE_FMT_FORMAT <fmt-vt/format.h>
105106
#define INCLUDE_FMT_RANGES <fmt-vt/ranges.h>
106107
#define INCLUDE_FMT_OSTREAM <fmt-vt/ostream.h>
107108

108-
#define VT_FMT_NAMESPACE namespace fmt::vt
109+
#define VT_FMT_NAMESPACE_BEGIN namespace fmt { inline namespace vt {
110+
#define VT_FMT_NAMESPACE_END } }
109111
#endif

src/vt/elm/elm_id.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct hash<vt::elm::ElementIDStruct> {
9797
#include "vt/cmake_config.h"
9898
#include INCLUDE_FMT_FORMAT
9999

100-
namespace fmt {
100+
VT_FMT_NAMESPACE_BEGIN
101101

102102
/// Custom fmt formatter/print for \c vt::elm::ElementIDStruct
103103
template <>
@@ -138,6 +138,6 @@ struct formatter<::vt::elm::ElementIDStruct> {
138138
}
139139
};
140140

141-
} /* end namespace fmt */
141+
VT_FMT_NAMESPACE_END
142142

143143
#endif /*INCLUDED_VT_ELM_ELM_ID_H*/

src/vt/epoch/epoch_type.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct hash<vt::epoch::EpochType> {
111111
#include "vt/cmake_config.h"
112112
#include INCLUDE_FMT_FORMAT
113113

114-
namespace fmt {
114+
VT_FMT_NAMESPACE_BEGIN
115115

116116
/// Custom fmt formatter/print for \c EpochType
117117
template <>
@@ -151,7 +151,7 @@ struct formatter<::vt::epoch::EpochType> {
151151
}
152152
};
153153

154-
} /* end namespace fmt */
154+
VT_FMT_NAMESPACE_END
155155

156156
namespace vt {
157157

src/vt/rdma/rdma_common.h

+28-23
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,35 @@ static constexpr ByteType rdma_default_byte_size = sizeof(char);
117117

118118
}} //end namespace vt::rdma
119119

120-
VT_FMT_NAMESPACE {
121-
template <>
122-
struct formatter<::vt::rdma::Type> : formatter<std::string_view> {
123-
template <typename FormatContext>
124-
auto format(::vt::rdma::Type t, FormatContext& ctx) {
125-
std::string_view name = "Unknown";
126-
switch (t) {
127-
case ::vt::rdma::Type::Get:
128-
name = "Get";
129-
break;
130-
case ::vt::rdma::Type::Put:
131-
name = "Put";
132-
break;
133-
case ::vt::rdma::Type::GetOrPut:
134-
name = "GetOrPut";
135-
break;
136-
case ::vt::rdma::Type::Uninitialized:
137-
name = "Uninitialized";
138-
break;
139-
}
140-
return formatter<std::string_view>::format(name, ctx);
120+
VT_FMT_NAMESPACE_BEGIN
121+
122+
template <>
123+
struct formatter<::vt::rdma::Type> : formatter<std::string_view> {
124+
template <typename FormatContext>
125+
auto format(::vt::rdma::Type t, FormatContext& ctx) {
126+
std::string_view name = "Unknown";
127+
switch (t) {
128+
case ::vt::rdma::Type::Get:
129+
name = "Get";
130+
break;
131+
case ::vt::rdma::Type::Put:
132+
name = "Put";
133+
break;
134+
case ::vt::rdma::Type::GetOrPut:
135+
name = "GetOrPut";
136+
break;
137+
case ::vt::rdma::Type::Uninitialized:
138+
name = "Uninitialized";
139+
break;
140+
default:
141+
name = fmt::format(
142+
"{}", static_cast<std::underlying_type_t<::vt::rdma::Type>>(t));
141143
}
142-
};
143-
} // VT_FMT_NAMESPACE
144+
return formatter<std::string_view>::format(name, ctx);
145+
}
146+
};
147+
148+
VT_FMT_NAMESPACE_END
144149

145150
#define PRINT_CHANNEL_TYPE(rdma_op_type) ( \
146151
rdma_op_type == vt::rdma::Type::Get ? "rdma::Get" : ( \

src/vt/termination/interval/interval.h

+15-13
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,20 @@ struct Interval;
237237

238238
}}}
239239

240-
VT_FMT_NAMESPACE {
241-
template <typename DomainT, DomainT sentinel>
242-
struct formatter<::vt::term::interval::Interval<DomainT, sentinel>>
243-
: formatter<std::string> {
244-
template <typename FormatContext>
245-
auto format(
246-
const ::vt::term::interval::Interval<DomainT, sentinel>& interval,
247-
FormatContext& ctx) {
248-
return format_to(
249-
ctx.out(), "Interval[{}, {}]", interval.lower(), interval.upper());
250-
}
251-
};
252-
} // VT_FMT_NAMESPACE
240+
VT_FMT_NAMESPACE_BEGIN
241+
242+
template <typename DomainT, DomainT sentinel>
243+
struct formatter<::vt::term::interval::Interval<DomainT, sentinel>>
244+
: formatter<std::string> {
245+
template <typename FormatContext>
246+
auto format(
247+
const ::vt::term::interval::Interval<DomainT, sentinel>& interval,
248+
FormatContext& ctx) {
249+
return format_to(
250+
ctx.out(), "Interval[{}, {}]", interval.lower(), interval.upper());
251+
}
252+
};
253+
254+
VT_FMT_NAMESPACE_END
253255

254256
#endif /*INCLUDED_VT_TERMINATION_INTERVAL_INTERVAL_H*/

src/vt/timing/timing.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,7 @@ TimeType getCurrentTime();
6363

6464
}} /* end namespace vt::timing */
6565

66-
VT_FMT_NAMESPACE {
67-
template <>
68-
struct formatter<::vt::TimeTypeWrapper> {
69-
template <typename ParseContext>
70-
constexpr auto parse(ParseContext& ctx) {
71-
return ctx.begin();
72-
}
66+
VT_FMT_NAMESPACE_BEGIN
7367

7468
template <typename FormatContext>
7569
auto format(::vt::TimeTypeWrapper const& t, FormatContext& ctx) {
@@ -80,6 +74,14 @@ VT_FMT_NAMESPACE {
8074
}
8175
};
8276

83-
} // VT_FMT_NAMESPACE
77+
template <typename FormatContext>
78+
auto format(::vt::TimeTypeWrapper const& t, FormatContext& ctx) {
79+
return fmt::format_to(
80+
ctx.out(), "{}",
81+
to_engineering_string(t.seconds(), 3, eng_exponential, "s"));
82+
}
83+
};
84+
85+
VT_FMT_NAMESPACE_END
8486

8587
#endif /*INCLUDED_VT_TIMING_TIMING_H*/

src/vt/topos/index/dense/dense_array.h

+14-12
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,20 @@ static_assert(
159159

160160
}} // end namespace vt::index
161161

162-
VT_FMT_NAMESPACE {
163-
template <typename IndexType, ::vt::index::NumDimensionsType ndim>
164-
struct formatter<::vt::index::DenseIndexArray<IndexType, ndim>>
165-
: formatter<std::array<IndexType, ndim>> {
166-
template <typename FormatContext>
167-
auto format(
168-
const ::vt::index::DenseIndexArray<IndexType, ndim>& wrapper,
169-
FormatContext& ctx) {
170-
return formatter<std::array<IndexType, ndim>>::format(wrapper.dims, ctx);
171-
}
172-
};
173-
} // VT_FMT_NAMESPACE
162+
VT_FMT_NAMESPACE_BEGIN
163+
164+
template <typename IndexType, ::vt::index::NumDimensionsType ndim>
165+
struct formatter<::vt::index::DenseIndexArray<IndexType, ndim>>
166+
: formatter<std::array<IndexType, ndim>> {
167+
template <typename FormatContext>
168+
auto format(
169+
const ::vt::index::DenseIndexArray<IndexType, ndim>& wrapper,
170+
FormatContext& ctx) {
171+
return formatter<std::array<IndexType, ndim>>::format(wrapper.dims, ctx);
172+
}
173+
};
174+
175+
VT_FMT_NAMESPACE_END
174176

175177
#include "vt/topos/index/dense/dense_array.impl.h"
176178

src/vt/vrt/collection/balance/greedylb/greedylb.h

+30-22
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
//@HEADER
4242
*/
4343

44+
#include <type_traits>
4445
#if !defined INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H
4546
#define INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H
4647

@@ -126,29 +127,36 @@ struct GreedyLB : LoadSamplerBaseLB {
126127

127128
}}}} /* end namespace vt::vrt::collection::lb */
128129

129-
VT_FMT_NAMESPACE {
130-
template <>
131-
struct formatter<::vt::vrt::collection::lb::DataDistStrategy>
132-
: formatter<std::string_view> {
133-
template <typename FormatContext>
134-
auto
135-
format(::vt::vrt::collection::lb::DataDistStrategy c, FormatContext& ctx) {
136-
std::string_view name = "Unknown";
137-
switch (c) {
138-
case ::vt::vrt::collection::lb::DataDistStrategy::scatter:
139-
name = "scatter";
140-
break;
141-
case ::vt::vrt::collection::lb::DataDistStrategy::bcast:
142-
name = "bcast";
143-
break;
144-
case ::vt::vrt::collection::lb::DataDistStrategy::pt2pt:
145-
name = "pt2pt";
146-
break;
147-
}
148-
return formatter<string_view>::format(name, ctx);
130+
VT_FMT_NAMESPACE_BEGIN
131+
132+
template <>
133+
struct formatter<::vt::vrt::collection::lb::DataDistStrategy>
134+
: formatter<std::string_view> {
135+
template <typename FormatContext>
136+
auto
137+
format(::vt::vrt::collection::lb::DataDistStrategy c, FormatContext& ctx) {
138+
std::string_view name = "Unknown";
139+
switch (c) {
140+
case ::vt::vrt::collection::lb::DataDistStrategy::scatter:
141+
name = "scatter";
142+
break;
143+
case ::vt::vrt::collection::lb::DataDistStrategy::bcast:
144+
name = "bcast";
145+
break;
146+
case ::vt::vrt::collection::lb::DataDistStrategy::pt2pt:
147+
name = "pt2pt";
148+
break;
149+
default:
150+
name = fmt::format(
151+
"{}",
152+
static_cast<
153+
std::underlying_type_t<::vt::vrt::collection::lb::DataDistStrategy>>(
154+
c));
149155
}
150-
};
156+
return formatter<string_view>::format(name, ctx);
157+
}
158+
};
151159

152-
} // VT_FMT_NAMESPACE
160+
VT_FMT_NAMESPACE_END
153161

154162
#endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H*/

src/vt/vrt/collection/balance/lb_args_enum_converter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct LBArgsEnumConverter {
100100
auto err = fmt::format(
101101
"LBArgsEnumConverter: enum '{}' value '{}' corresponding to LB "
102102
"argument '{}' does not have a string associated with it",
103-
enum_type_, e, par_name_
103+
enum_type_, static_cast<std::underlying_type_t<T>>(e), par_name_
104104
);
105105
vtAbort(err);
106106
}

src/vt/vrt/collection/balance/temperedlb/criterion.h

+19-19
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,26 @@ struct Criterion {
9393

9494
}}}} /* end namespace vt::vrt::collection::lb */
9595

96-
VT_FMT_NAMESPACE {
97-
template <>
98-
struct formatter<::vt::vrt::collection::lb::CriterionEnum>
99-
: formatter<std::string_view> {
100-
template <typename FormatContext>
101-
auto
102-
format(::vt::vrt::collection::lb::CriterionEnum c, FormatContext& ctx) {
103-
std::string_view name = "Unknown";
104-
switch (c) {
105-
case ::vt::vrt::collection::lb::CriterionEnum::Grapevine:
106-
name = "Grapevine";
107-
break;
108-
case ::vt::vrt::collection::lb::CriterionEnum::ModifiedGrapevine:
109-
name = "ModifiedGrapevine";
110-
break;
111-
}
112-
return formatter<string_view>::format(name, ctx);
96+
VT_FMT_NAMESPACE_BEGIN
97+
98+
template <>
99+
struct formatter<::vt::vrt::collection::lb::CriterionEnum>
100+
: formatter<std::string_view> {
101+
template <typename FormatContext>
102+
auto format(::vt::vrt::collection::lb::CriterionEnum c, FormatContext& ctx) {
103+
std::string_view name = "Unknown";
104+
switch (c) {
105+
case ::vt::vrt::collection::lb::CriterionEnum::Grapevine:
106+
name = "Grapevine";
107+
break;
108+
case ::vt::vrt::collection::lb::CriterionEnum::ModifiedGrapevine:
109+
name = "ModifiedGrapevine";
110+
break;
113111
}
114-
};
112+
return formatter<string_view>::format(name, ctx);
113+
}
114+
};
115115

116-
} // VT_FMT_NAMESPACE
116+
VT_FMT_NAMESPACE_END
117117

118118
#endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_CRITERION_H*/

0 commit comments

Comments
 (0)