47
47
#include " vt/configs/types/types_type.h"
48
48
#include " vt/configs/types/types_sentinels.h"
49
49
50
+ #include " vt/cmake_config.h"
51
+ #include INCLUDE_FMT_FORMAT
52
+
50
53
namespace vt { namespace elm {
51
54
52
55
// / The underlying element ID type
@@ -81,6 +84,12 @@ struct ElementIDStruct {
81
84
bool isLocatedOnThisNode () const ;
82
85
};
83
86
87
+ inline auto format_as (ElementIDStruct e) {
88
+ auto fmt_str = " ({},{},{},{})" ;
89
+ return fmt::format (
90
+ fmt_str, e.id , e.getHomeNode (), e.curr_node , e.isMigratable ()
91
+ );
92
+ }
84
93
85
94
}} /* end namespace vt::elm */
86
95
@@ -95,50 +104,4 @@ struct hash<vt::elm::ElementIDStruct> {
95
104
96
105
} /* end namespace std */
97
106
98
- #include " vt/cmake_config.h"
99
- #include INCLUDE_FMT_FORMAT
100
-
101
- VT_FMT_NAMESPACE_BEGIN
102
-
103
- // / Custom fmt formatter/print for \c vt::elm::ElementIDStruct
104
- template <>
105
- struct formatter <::vt::elm::ElementIDStruct> {
106
- // / Presentation format:
107
- // / - 'x' - hex (default)
108
- // / - 'd' - decimal
109
- // / - 'b' - binary
110
- char presentation = ' x' ;
111
-
112
- // / Parses format specifications of the form ['x' | 'd' | 'b'].
113
- auto parse (format_parse_context& ctx) -> decltype(ctx.begin()) {
114
- // Parse the presentation format and store it in the formatter:
115
- auto it = ctx.begin (), end = ctx.end ();
116
- if (it != end && (*it == ' x' || *it == ' d' || *it == ' b' )) {
117
- presentation = *it++;
118
- }
119
-
120
- // Check if reached the end of the range:
121
- if (it != end && *it != ' }' ) {
122
- throw format_error (" invalid format" );
123
- }
124
-
125
- // Return an iterator past the end of the parsed range:
126
- return it;
127
- }
128
-
129
- // / Formats the epoch using the parsed format specification (presentation)
130
- // / stored in this formatter.
131
- template <typename FormatContext>
132
- auto format (::vt::elm::ElementIDStruct const & e, FormatContext& ctx) const {
133
- std::string id_format =
134
- presentation == ' b' ? " {:b}" : (presentation == ' d' ? " {:d}" : " {:x}" );
135
- auto fmt_str = " (" + id_format + " ,{},{},{})" ;
136
- return format_to (
137
- ctx.out (), fmt_str, e.id , e.getHomeNode (), e.curr_node , e.isMigratable ()
138
- );
139
- }
140
- };
141
-
142
- VT_FMT_NAMESPACE_END
143
-
144
107
#endif /* INCLUDED_VT_ELM_ELM_ID_H*/
0 commit comments