mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 03:07:36 +02:00
Added formatter for bit_reference-like types (#3570)
* Add test for std::vector<bool>::reference Co-authored-by: Felix <felix-antoine.constantin@polymtl.ca> Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru> * Add test for std::bitset<N>::reference Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru> * Add test for const std::bitset<N>::reference and const std::vector<bool>::reference Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru> * Add bit_reference-like formatter Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru> * Use std::addressof Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru> --------- Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru> Co-authored-by: Felix <felix-antoine.constantin@polymtl.ca>
This commit is contained in:
committed by
GitHub
parent
96d1fa22d4
commit
aeb6ad4dd0
@ -7,6 +7,7 @@
|
||||
|
||||
#include "fmt/std.h"
|
||||
|
||||
#include <bitset>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -221,3 +222,17 @@ TEST(std_test, exception) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(std_test, format_bit_reference) {
|
||||
std::bitset<2> bs(1);
|
||||
EXPECT_EQ(fmt::format("{} {}", bs[0], bs[1]), "true false");
|
||||
std::vector<bool> v = {true, false};
|
||||
EXPECT_EQ(fmt::format("{} {}", v[0], v[1]), "true false");
|
||||
}
|
||||
|
||||
TEST(std_test, format_const_bit_reference) {
|
||||
const std::bitset<2> bs(1);
|
||||
EXPECT_EQ(fmt::format("{} {}", bs[0], bs[1]), "true false");
|
||||
const std::vector<bool> v = {true, false};
|
||||
EXPECT_EQ(fmt::format("{} {}", v[0], v[1]), "true false");
|
||||
}
|
||||
|
Reference in New Issue
Block a user