Merge branch 'fmtlib:master' into cuda_agnostic_fractional_part_rounding_thresholds

This commit is contained in:
Cazadorro 2026-03-29 00:31:28 -04:00 committed by GitHub
commit 5d044de383
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 65 additions and 43 deletions

View File

@ -33,6 +33,10 @@ jobs:
std: 23
install: sudo apt install g++-13
shared: -DBUILD_SHARED_LIBS=ON
- cxx: g++-14
build_type: Release
std: 23
install: sudo apt install g++-14
- cxx: clang++-11
build_type: Debug
std: 17
@ -55,6 +59,11 @@ jobs:
std: 20
cxxflags: -stdlib=libc++
install: sudo apt install libc++-14-dev libc++abi-14-dev
- cxx: clang++-20
build_type: Debug
std: 20
cxxflags: -stdlib=libc++
install: sudo apt install clang-20 libc++-20-dev libc++abi-20-dev
steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
@ -131,7 +140,14 @@ jobs:
- name: Add repositories for newer GCC
run: |
sudo apt-add-repository ppa:ubuntu-toolchain-r/test
if: ${{ matrix.cxx == 'g++-13' }}
if: ${{ matrix.cxx == 'g++-13' || matrix.cxx == 'g++-14' }}
- name: Install LLVM-20
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 20
if: ${{ matrix.cxx == 'clang++-20' }}
- name: Add Ubuntu mirrors
run: |
@ -164,6 +180,23 @@ jobs:
-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON \
-DFMT_DOC=OFF -DFMT_PEDANTIC=ON -DFMT_WERROR=ON \
${{matrix.fuzz}} ${{matrix.shared}} $GITHUB_WORKSPACE
if: ${{ matrix.cxx != 'clang++-20' && matrix.cxx != 'g++-14' }}
- name: Configure-Modules
working-directory: ${{runner.workspace}}/build
env:
CXX: ${{matrix.cxx}}
CXXFLAGS: ${{matrix.cxxflags}}
run: |
cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DCMAKE_CXX_EXTENSIONS=OFF \
-G Ninja \
-DCMAKE_CXX_VISIBILITY_PRESET=hidden \
-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON \
-DFMT_DOC=OFF -DFMT_PEDANTIC=ON \
${{matrix.fuzz}} ${{matrix.shared}} $GITHUB_WORKSPACE
if: ${{ matrix.cxx == 'clang++-20' || matrix.cxx == 'g++-14' }}
- name: Build
working-directory: ${{runner.workspace}}/build

View File

@ -1859,42 +1859,38 @@ class fixed_buffer_traits {
};
template <typename OutputIt, typename InputIt, typename = void>
struct has_back_insert_iterator_container_append : std::false_type {};
struct has_append : std::false_type {};
template <typename OutputIt, typename InputIt>
struct has_back_insert_iterator_container_append<
OutputIt, InputIt,
void_t<decltype(get_container(std::declval<OutputIt>())
.append(std::declval<InputIt>(),
std::declval<InputIt>()))>> : std::true_type {};
struct has_append<OutputIt, InputIt,
void_t<decltype(get_container(std::declval<OutputIt>())
.append(std::declval<InputIt>(),
std::declval<InputIt>()))>>
: std::true_type {};
template <typename OutputIt, typename InputIt, typename = void>
struct has_back_insert_iterator_container_insert_at_end : std::false_type {};
template <typename OutputIt, typename T, typename = void>
struct has_insert : std::false_type {};
template <typename OutputIt, typename InputIt>
struct has_back_insert_iterator_container_insert_at_end<
OutputIt, InputIt,
void_t<decltype(get_container(std::declval<OutputIt>())
.insert(get_container(std::declval<OutputIt>()).end(),
std::declval<InputIt>(),
std::declval<InputIt>()))>> : std::true_type {};
template <typename OutputIt, typename T>
struct has_insert<OutputIt, T,
void_t<decltype(get_container(std::declval<OutputIt>())
.insert({}, std::declval<T>(),
std::declval<T>()))>>
: std::true_type {};
// An optimized version of std::copy with the output value type (T).
template <typename T, typename InputIt, typename OutputIt,
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value&&
has_back_insert_iterator_container_append<
OutputIt, InputIt>::value)>
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>() &&
has_append<OutputIt, InputIt>())>
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
get_container(out).append(begin, end);
return out;
}
template <typename T, typename InputIt, typename OutputIt,
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value &&
!has_back_insert_iterator_container_append<
OutputIt, InputIt>::value &&
has_back_insert_iterator_container_insert_at_end<
OutputIt, InputIt>::value)>
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>() &&
!has_append<OutputIt, InputIt>() &&
has_insert<OutputIt, InputIt>())>
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
auto& c = get_container(out);
c.insert(c.end(), begin, end);
@ -1902,21 +1898,14 @@ FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
}
template <typename T, typename InputIt, typename OutputIt,
FMT_ENABLE_IF(!(is_back_insert_iterator<OutputIt>::value &&
(has_back_insert_iterator_container_append<
OutputIt, InputIt>::value ||
has_back_insert_iterator_container_insert_at_end<
OutputIt, InputIt>::value)))>
FMT_ENABLE_IF(!is_back_insert_iterator<OutputIt>() ||
!(has_append<OutputIt, InputIt>() ||
has_insert<OutputIt, InputIt>()))>
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
while (begin != end) *out++ = static_cast<T>(*begin++);
return out;
}
template <typename T, typename V, typename OutputIt>
FMT_CONSTEXPR auto copy(basic_string_view<V> s, OutputIt out) -> OutputIt {
return copy<T>(s.begin(), s.end(), out);
}
// A buffer that writes to an output iterator when flushed.
template <typename OutputIt, typename T, typename Traits = buffer_traits>
class iterator_buffer : public Traits, public buffer<T> {
@ -1934,12 +1923,7 @@ class iterator_buffer : public Traits, public buffer<T> {
this->clear();
const T* begin = data_;
const T* end = begin + this->limit(size);
#if defined(__cpp_if_constexpr)
if constexpr (std::is_move_assignable<OutputIt>::value)
out_ = copy<T>(begin, end, out_);
else
#endif
while (begin != end) *out_++ = *begin++;
out_ = copy<T>(begin, end, out_);
}
public:

View File

@ -548,6 +548,11 @@ FMT_CONSTEXPR20 auto fill_n(T* out, Size count, char value) -> T* {
return out + count;
}
template <typename T, typename V, typename OutputIt>
FMT_CONSTEXPR auto copy(basic_string_view<V> s, OutputIt out) -> OutputIt {
return copy<T>(s.begin(), s.end(), out);
}
template <typename OutChar, typename InputIt, typename OutputIt>
FMT_CONSTEXPR FMT_NOINLINE auto copy_noinline(InputIt begin, InputIt end,
OutputIt out) -> OutputIt {

View File

@ -811,10 +811,10 @@ TEST(base_test, throw_in_buffer_dtor) {
constexpr int buffer_size = 256;
struct throwing_iterator {
int& count;
int* count;
auto operator=(char) -> throwing_iterator& {
if (++count > buffer_size) throw std::exception();
if (++*count > buffer_size) throw std::exception();
return *this;
}
auto operator*() -> throwing_iterator& { return *this; }
@ -824,7 +824,7 @@ TEST(base_test, throw_in_buffer_dtor) {
try {
int count = 0;
fmt::format_to(throwing_iterator{count}, fmt::runtime("{:{}}{"), "",
fmt::format_to(throwing_iterator{&count}, fmt::runtime("{:{}}{"), "",
buffer_size + 1);
} catch (const std::exception&) {
}