Skip to content

Commit

Permalink
Merge branch 'upstream' of github.com:kassane/fmt into zig-pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Dec 29, 2023
2 parents 10a2e47 + ea1066b commit 3577865
Show file tree
Hide file tree
Showing 23 changed files with 1,268 additions and 962 deletions.
140 changes: 138 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,140 @@
# 10.2.0 - TBD

- Added support for the `%j` specifier (the number of days) for
`std::chrono::duration` (https://github.com/fmtlib/fmt/issues/3643,
https://github.com/fmtlib/fmt/pull/3732). Thanks @intelfx.

- Added support for the chrono suffix for days and changed
the suffix for minutes from "m" to the correct "min"
(https://github.com/fmtlib/fmt/pull/3664).
For example ([godbolt](https://godbolt.org/z/9KhMnq9ba)):

```c++
#include <fmt/chrono.h>

int main() {
fmt::print("{}\n", std::chrono::days(42)); // prints "42d"
}
```

Thanks @Richardk2n.

- Fixed an overflow in `std::chrono::time_point` formatting with large dates
(https://github.com/fmtlib/fmt/issues/3725,
https://github.com/fmtlib/fmt/pull/3727). Thanks @cschreib.

- Added a formatter for `std::source_location`
(https://github.com/fmtlib/fmt/pull/3730). For example
([godbolt](https://godbolt.org/z/YajfKjhhr)):

```c++
#include <fmt/chrono.h>

int main() {
fmt::print("{}\n", std::source_location::current());
}
```

prints

```
/app/example.cpp:5:51: int main()
```

Thanks @felix642.

- Added a formatter for `std::bitset`
(https://github.com/fmtlib/fmt/pull/3660).
For example ([godbolt](https://godbolt.org/z/bdEaGeYxe)):

```c++
#include <bitset>
#include <fmt/std.h>

int main() {
fmt::print("{}\n", std::bitset<6>(42)); // prints "101010"
}
```

Thanks @muggenhor.

- Added the generic representation (`g`) to `std::filesystem::path`
(https://github.com/fmtlib/fmt/issues/3715,
https://github.com/fmtlib/fmt/pull/3729). For example:

```c++
#include <filesystem>
#include <fmt/std.h>

int main() {
fmt::print("{:g}\n", std::filesystem::path("C:\\foo"));
}
```

prints `"C:/foo"` on Windows.

Thanks @js324.

- Added synchronization with the underlying output stream when writing to
the Windows console
(https://github.com/fmtlib/fmt/pull/3668,
https://github.com/fmtlib/fmt/issues/3688,
https://github.com/fmtlib/fmt/pull/3689).
Thanks @Roman-Koshelev and @dimztimz.

- Changed to only export `format_error` when {fmt} is built as a shared
library (https://github.com/fmtlib/fmt/issues/3626,
https://github.com/fmtlib/fmt/pull/3627). Thanks @phprus.

- Made `fmt::streamed` `constexpr`.
(https://github.com/fmtlib/fmt/pull/3650). Thanks @muggenhor.

- Added an option to build without `wchar_t` support on Windows
(https://github.com/fmtlib/fmt/pull/3636). Thanks @glebm.

- Improved build configuration
(https://github.com/fmtlib/fmt/issues/3701,
https://github.com/fmtlib/fmt/pull/3702). Thanks @pklima.

- Fixed various warnings and compilation issues
(https://github.com/fmtlib/fmt/pull/3610,
https://github.com/fmtlib/fmt/pull/3624,
https://github.com/fmtlib/fmt/pull/3630,
https://github.com/fmtlib/fmt/pull/3634,
https://github.com/fmtlib/fmt/pull/3638,
https://github.com/fmtlib/fmt/issues/3645,
https://github.com/fmtlib/fmt/pull/3647,
https://github.com/fmtlib/fmt/pull/3652,
https://github.com/fmtlib/fmt/issues/3654,
https://github.com/fmtlib/fmt/pull/3663,
https://github.com/fmtlib/fmt/pull/3680,
https://github.com/fmtlib/fmt/pull/3695,
https://github.com/fmtlib/fmt/pull/369,
https://github.com/fmtlib/fmt/issues/3712,
https://github.com/fmtlib/fmt/pull/3713,
https://github.com/fmtlib/fmt/pull/3716,
https://github.com/fmtlib/fmt/pull/3723).
Thanks @danakj, @vinayyadav3016, @cyyever, @phprus, @qimiko, @saschasc,
@gsjaardema, @lazka, @Zhaojun-Liu, @carlsmedstad, @hotwatermorning,
@cptFracassa, @kuguma, @PeterJohnson .

- Improved documentation and README
(https://github.com/fmtlib/fmt/pull/3642,
https://github.com/fmtlib/fmt/pull/3653,
https://github.com/fmtlib/fmt/pull/3655,
https://github.com/fmtlib/fmt/pull/3661,
https://github.com/fmtlib/fmt/issues/3673,
https://github.com/fmtlib/fmt/pull/3677).
Thanks @idzm, @perlun, @joycebrum, @fennewald.

- Updated CI dependencies
(https://github.com/fmtlib/fmt/pull/3615,
https://github.com/fmtlib/fmt/pull/3622,
https://github.com/fmtlib/fmt/pull/3623,
https://github.com/fmtlib/fmt/pull/3666,
https://github.com/fmtlib/fmt/pull/3696,
https://github.com/fmtlib/fmt/pull/3697).

# 10.1.1 - 2023-08-28

- Added formatters for `std::atomic` and `atomic_flag`
Expand All @@ -13,8 +150,7 @@
https://github.com/fmtlib/fmt/pull/3605).
Thanks @MathewBensonCode.
- Made `fmt::to_string` work with types that have `format_as`
overloads (https://github.com/fmtlib/fmt/pull/3575).
Thanks @phprus.
overloads (https://github.com/fmtlib/fmt/pull/3575). Thanks @phprus.
- Made `formatted_size` work with integral format specifiers at
compile time (https://github.com/fmtlib/fmt/pull/3591).
Thanks @elbeno.
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@ std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
// s == "I'd rather be happy than right."
```

**Print chrono durations** ([run](https://godbolt.org/z/K8s4Mc))
**Print dates and times** ([run](https://godbolt.org/z/c31ExdY3W))

``` c++
#include <fmt/chrono.h>

int main() {
using namespace std::literals::chrono_literals;
fmt::print("Default format: {} {}\n", 42s, 100ms);
fmt::print("strftime-like format: {:%H:%M:%S}\n", 3h + 15min + 30s);
auto now = std::chrono::system_clock::now();
fmt::print("Date and time: {}\n", now);
fmt::print("Time: {:%H:%M}\n", now);
}
```

Output:

Default format: 42s 100ms
strftime-like format: 03:15:30
Date and time: 2023-12-26 19:10:31.557195597
Time: 19:10

**Print a container** ([run](https://godbolt.org/z/MxM1YqjE7))

Expand Down
8 changes: 7 additions & 1 deletion doc/syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The general form of a *standard format specifier* is:
width: `integer` | "{" [`arg_id`] "}"
precision: `integer` | "{" [`arg_id`] "}"
type: "a" | "A" | "b" | "B" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" |
: "o" | "p" | "s" | "x" | "X"
: "o" | "p" | "s" | "x" | "X" | "?"

The *fill* character can be any Unicode code point other than ``'{'`` or
``'}'``. The presence of a fill character is signaled by the character following
Expand Down Expand Up @@ -177,6 +177,9 @@ The available string presentation types are:
| ``'s'`` | String format. This is the default type for strings and |
| | may be omitted. |
+---------+----------------------------------------------------------+
| ``'?'`` | Debug format. The string is quoted and special |
| | characters escaped. |
+---------+----------------------------------------------------------+
| none | The same as ``'s'``. |
+---------+----------------------------------------------------------+

Expand All @@ -188,6 +191,9 @@ The available character presentation types are:
| ``'c'`` | Character format. This is the default type for |
| | characters and may be omitted. |
+---------+----------------------------------------------------------+
| ``'?'`` | Debug format. The character is quoted and special |
| | characters escaped. |
+---------+----------------------------------------------------------+
| none | The same as ``'c'``. |
+---------+----------------------------------------------------------+

Expand Down
11 changes: 6 additions & 5 deletions include/fmt/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ template <typename T> struct is_reference_wrapper : std::false_type {};
template <typename T>
struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type {};

template <typename T> const T& unwrap(const T& v) { return v; }
template <typename T> const T& unwrap(const std::reference_wrapper<T>& v) {
template <typename T> auto unwrap(const T& v) -> const T& { return v; }
template <typename T>
auto unwrap(const std::reference_wrapper<T>& v) -> const T& {
return static_cast<const T&>(v);
}

Expand All @@ -50,7 +51,7 @@ class dynamic_arg_list {
std::unique_ptr<node<>> head_;

public:
template <typename T, typename Arg> const T& push(const Arg& arg) {
template <typename T, typename Arg> auto push(const Arg& arg) -> const T& {
auto new_node = std::unique_ptr<typed_node<T>>(new typed_node<T>(arg));
auto& value = new_node->value;
new_node->next = std::move(head_);
Expand Down Expand Up @@ -110,14 +111,14 @@ class dynamic_format_arg_store

friend class basic_format_args<Context>;

unsigned long long get_types() const {
auto get_types() const -> unsigned long long {
return detail::is_unpacked_bit | data_.size() |
(named_info_.empty()
? 0ULL
: static_cast<unsigned long long>(detail::has_named_args_bit));
}

const basic_format_arg<Context>* data() const {
auto data() const -> const basic_format_arg<Context>* {
return named_info_.empty() ? data_.data() : data_.data() + 1;
}

Expand Down
Loading

0 comments on commit 3577865

Please sign in to comment.