Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
format.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
21
22#include "sham/format/aliases.hpp" // IWYU pragma: export
24#include <fmt/printf.h>
25
26namespace sham {
27
39 inline __attribute__((always_inline)) auto vformat(std::string_view fmt, fmt::format_args args)
40 -> std::string {
41 try {
42 return fmt::vformat(fmt, args);
43 } catch (const std::exception &e) {
44 throw make_format_exception("vformat", e.what(), std::string(fmt));
45 }
46 }
47
59 inline __attribute__((always_inline)) auto vformat(fmt::string_view fmt, fmt::format_args args)
60 -> std::string {
61 try {
62 return fmt::vformat(fmt, args);
63 } catch (const std::exception &e) {
64 throw make_format_exception("vformat", e.what(), fmt::to_string(fmt));
65 }
66 }
67
81 template<typename... T>
82 inline __attribute__((always_inline)) auto format(fmt::format_string<T...> fmt, T &&...args)
83 -> std::string {
84 return sham::vformat(fmt, fmt::make_format_args(args...));
85 }
86
100 template<typename... T>
101 inline __attribute__((always_inline)) auto format_printf(
102 std::string_view format, const T &...args) -> std::string {
103 try {
104 return fmt::sprintf(format, args...);
105 } catch (const std::exception &e) {
106 throw make_format_exception("printf", e.what(), std::string(format));
107 }
108 }
109
110} // namespace sham
111
112// Re-export all sham::format symbols into shambase for backwards compatibility
113namespace shambase {
114
115 using ::sham::format;
116 using ::sham::format_printf;
117 using ::sham::vformat;
118
119} // namespace shambase
Type aliases for fmt types used throughout shamformat.
Declaration of the custom format exception builder system.
namespace for backends this one is named only sham since shambackends is too long to write
sham::format_error make_format_exception(std::string_view function_call, std::string_view what, const std::string &fmt_string, std::source_location loc=std::source_location::current())
Create a format error exception.
namespace for basic c++ utilities
std::vector< std::string_view > args
Executable argument list (mapped from argv).
Definition cmdopt.cpp:63