Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
format.hpp
Go to the documentation of this file.
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Smith Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
13 #pragma once
14 
15 #include <format>
16 #include <sstream>
17 #include <string>
18 #include <string_view>
19 
20 namespace smith::format {
21 
23 template <typename T>
24 std::string streamed(const T& value)
25 {
26  std::ostringstream stream;
27  stream << value;
28  return stream.str();
29 }
30 
34  constexpr auto parse(std::format_parse_context& ctx) const { return ctx.begin(); }
35 
37  template <typename T>
38  auto format(const T& value, std::format_context& ctx) const
39  {
40  return std::formatter<std::string_view>{}.format(streamed(value), ctx);
41  }
42 };
43 
44 } // namespace smith::format
std::string streamed(const T &value)
Converts a value to a string using its stream insertion operator.
Definition: format.hpp:24
Formatter that renders values through operator<<.
Definition: format.hpp:32
auto format(const T &value, std::format_context &ctx) const
Formats a value by streaming it to a temporary string.
Definition: format.hpp:38
constexpr auto parse(std::format_parse_context &ctx) const
Accepts the default formatting syntax.
Definition: format.hpp:34