Skip to content

[libc++][format] Adds flat_(|multi)map formatter. #124418

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

Merged
merged 1 commit into from
Jan 27, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <concepts>
#include <deque>
#include <filesystem>
#include <flat_map>
#include <format>
#include <forward_list>
#include <list>
Expand Down Expand Up @@ -242,6 +243,13 @@ void test_P2286() {
assert_is_formattable<std::multiset<int>, CharT>();
assert_is_formattable<std::multimap<int, int>, CharT>();

#if TEST_STD_VER >= 23
// assert_is_formattable<std::flat_set<int>, CharT>();
assert_is_formattable<std::flat_map<int, int>, CharT>();
// assert_is_formattable<std::flat_multiset<int>, CharT>();
assert_is_formattable<std::flat_multimap<int, int>, CharT>();
#endif // TEST_STD_VER >= 2

assert_is_formattable<std::unordered_set<int>, CharT>();
assert_is_formattable<std::unordered_map<int, int>, CharT>();
assert_is_formattable<std::unordered_multiset<int>, CharT>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define TEST_STD_UTILITIES_FORMAT_FORMAT_RANGE_FORMAT_RANGE_FMTMAP_FORMAT_FUNCTIONS_TESTS_H

#include <algorithm>
#include <deque>
#include <flat_map>
#include <format>
#include <map>
#include <unordered_map>
Expand Down Expand Up @@ -241,10 +243,7 @@ void test_char_to_wchar(TestFunction check, ExceptionTest check_exception) {
// Bool
//
template <class CharT, class TestFunction, class ExceptionTest>
void test_bool(TestFunction check, ExceptionTest check_exception) {
// duplicates are stored in order of insertion
std::multimap<bool, int> input{{true, 42}, {false, 0}, {true, 1}};

void test_bool(TestFunction check, ExceptionTest check_exception, auto&& input) {
check(SV("{false: 0, true: 42, true: 1}"), SV("{}"), input);
check(SV("{false: 0, true: 42, true: 1}^42"), SV("{}^42"), input);
check(SV("{false: 0, true: 42, true: 1}^42"), SV("{:}^42"), input);
Expand Down Expand Up @@ -339,6 +338,17 @@ void test_bool(TestFunction check, ExceptionTest check_exception) {
"The argument index value is too large for the number of arguments supplied", SV("{:^^{}:#>{}}"), input, 41);
}

template <class CharT, class TestFunction, class ExceptionTest>
void test_bool(TestFunction check, ExceptionTest check_exception) {
// duplicates are stored in order of insertion
test_bool<CharT>(check, check_exception, std::multimap<bool, int>{{true, 42}, {false, 0}, {true, 1}});
#if TEST_STD_VER >= 23
test_bool<CharT>(check,
check_exception,
std::flat_multimap<bool, int, std::less<bool>, std::deque<bool>>{{true, 42}, {false, 0}, {true, 1}});
#endif
}

//
// Integral
//
Expand Down Expand Up @@ -442,6 +452,9 @@ void test_int(TestFunction check, ExceptionTest check_exception, auto&& input) {
template <class CharT, class TestFunction, class ExceptionTest>
void test_int(TestFunction check, ExceptionTest check_exception) {
test_int<CharT>(check, check_exception, std::map<int, int>{{1, -1}, {42, -42}, {-42, 42}});
#if TEST_STD_VER >= 23
test_int<CharT>(check, check_exception, std::flat_map<int, int>{{1, -1}, {42, -42}, {-42, 42}});
#endif
}

//
Expand Down
Loading