[libcxx-commits] [libcxx] [libcxx] Optimize std::generate for segmented iterators (PR #163006)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 16 19:43:30 PDT 2025
================
@@ -16,50 +16,54 @@
#include <algorithm>
#include <cassert>
+#include <deque>
#include "test_macros.h"
#include "test_iterators.h"
-struct gen_test
-{
- TEST_CONSTEXPR int operator()() const {return 1;}
+struct gen_test {
+ TEST_CONSTEXPR int operator()() const { return 1; }
};
-
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
- int ia[] = {0, 1, 2, 3, 4};
+ int ia[] = {0, 1, 2, 3, 4};
- std::generate(std::begin(ia), std::end(ia), gen_test());
+ std::generate(std::begin(ia), std::end(ia), gen_test());
- return std::all_of(std::begin(ia), std::end(ia), [](int x) { return x == 1; })
- ;
- }
+ return std::all_of(std::begin(ia), std::end(ia), [](int x) { return x == 1; });
+}
#endif
-
template <class Iter>
-void
-test()
-{
- const unsigned n = 4;
- int ia[n] = {0};
- std::generate(Iter(ia), Iter(ia+n), gen_test());
- assert(ia[0] == 1);
- assert(ia[1] == 1);
- assert(ia[2] == 1);
- assert(ia[3] == 1);
+void test() {
+ const unsigned n = 4;
+ int ia[n] = {0};
+ std::generate(Iter(ia), Iter(ia + n), gen_test());
+ assert(ia[0] == 1);
+ assert(ia[1] == 1);
+ assert(ia[2] == 1);
+ assert(ia[3] == 1);
+}
+
+void deque_test() {
----------------
frederick-vs-ja wrote:
Can we avoid formatting other functions? ("Format Selection" in VSCode can be used.)
https://github.com/llvm/llvm-project/pull/163006
More information about the libcxx-commits
mailing list