Lagrange
Loading...
Searching...
No Matches
print.h
1/*
2 * Copyright 2026 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
19
20#include <lagrange/utils/fmt/format.h>
21
22#if !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION >= 90000
23// clang-format off
24#include <lagrange/utils/warnoff.h>
25#include <spdlog/fmt/ostr.h>
26#include <lagrange/utils/warnon.h>
27// clang-format on
28#endif
29
30#include <ostream>
31
32namespace lagrange {
33
35template <typename... Args>
36void print(std::ostream& os, format_string<Args...> fmt_str, Args&&... args)
37{
38#if defined(SPDLOG_USE_STD_FORMAT)
39 // std::print is only available since C++23
40 os << std::format(fmt_str, std::forward<Args>(args)...);
41#elif FMT_VERSION >= 90000
42 // fmt v9+ accepts format_string<T...> directly in fmt::print(ostream, ...).
43 fmt::print(os, fmt_str, std::forward<Args>(args)...);
44#else
45 // fmt v8 uses `to_string_view(const S&)` internally, which doesn't recognize
46 // basic_format_string as a string-like type. Fall back to format + ostream write.
47 os << fmt::format(fmt_str, std::forward<Args>(args)...);
48#endif
49}
50
51} // namespace lagrange
Main namespace for Lagrange.
void print(std::ostream &os, format_string< Args... > fmt_str, Args &&... args)
Writes a formatted string to an output stream.
Definition print.h:36
Definition project.cpp:27