mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
Use std::string_view and fmtlib across all libraries (#3402)
- Twine, StringRef, Format, and NativeFormatting have been removed - Logging now uses fmtlib style formatting - Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or std::puts()/std::fputs() (for unformatted strings). - A wpi/fmt/raw_ostream.h header has been added to enable fmt::print() with wpi::raw_ostream
This commit is contained in:
30
wpiutil/src/main/native/include/wpi/fmt/raw_ostream.h
Normal file
30
wpiutil/src/main/native/include/wpi/fmt/raw_ostream.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#ifndef WPIUTIL_WPI_FMT_RAW_OSTREAM_H_
|
||||
#define WPIUTIL_WPI_FMT_RAW_OSTREAM_H_
|
||||
|
||||
#include "fmt/format.h"
|
||||
#include "wpi/raw_ostream.h"
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
inline void vprint(wpi::raw_ostream& os, string_view format_str,
|
||||
fmt::format_args args) {
|
||||
memory_buffer buffer;
|
||||
detail::vformat_to(buffer, format_str, args);
|
||||
os.write(buffer.data(), buffer.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints formatted data to the stream *os*.
|
||||
*/
|
||||
template <typename S, typename... Args>
|
||||
void print(wpi::raw_ostream& os, const S& format_str, Args&&... args) {
|
||||
vprint(os, format_str, fmt::make_args_checked<Args...>(format_str, args...));
|
||||
}
|
||||
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
#endif // WPIUTIL_WPI_FMT_RAW_OSTREAM_H_
|
||||
Reference in New Issue
Block a user