Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fmt::appender implement std::output_iterator concept #4093

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace std {
template <> struct iterator_traits<fmt::appender> {
using iterator_category = output_iterator_tag;
using value_type = char;
using difference_type = ptrdiff_t;
};
} // namespace std

Expand Down
8 changes: 1 addition & 7 deletions test/base-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ TEST(string_view_test, compare) {
}

TEST(base_test, is_locking) {
EXPECT_FALSE(fmt::detail::is_locking<const char (&)[3]>());
EXPECT_FALSE(fmt::detail::is_locking<const char(&)[3]>());
}

TEST(base_test, is_output_iterator) {
Expand All @@ -116,12 +116,6 @@ TEST(base_test, is_back_insert_iterator) {
std::front_insert_iterator<std::string>>::value);
}

TEST(base_test, buffer_appender) {
#ifdef __cpp_lib_ranges
EXPECT_TRUE((std::output_iterator<fmt::appender, char>));
#endif
}

#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 470
TEST(buffer_test, noncopyable) {
EXPECT_FALSE(std::is_copy_constructible<buffer<char>>::value);
Expand Down
7 changes: 7 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include <string> // std::string
#include <thread> // std::thread
#include <type_traits> // std::is_default_constructible
#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<version>)
# include <version>
#endif

#include "gtest-extra.h"
#include "mock-allocator.h"
Expand All @@ -42,6 +45,10 @@ using fmt::detail::uint128_fallback;
using testing::Return;
using testing::StrictMock;

#ifdef __cpp_lib_concepts
static_assert(std::output_iterator<fmt::appender, char>);
#endif

enum { buffer_size = 256 };

TEST(uint128_test, ctor) {
Expand Down