Specialized enable_borrowed_ranges for VectorwiseOp class range iteration

libeigen/eigen!2127

Closes #2882
This commit is contained in:
Blake
2026-02-15 10:31:33 -05:00
committed by Rasmus Munk Larsen
parent 1a2b80727c
commit d0654a201b
4 changed files with 55 additions and 6 deletions

View File

@@ -0,0 +1,31 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#define TEST_ENABLE_TEMPORARY_TRACKING
#include "main.h"
#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L
#include <ranges>
#endif
void vectorwiseop_use_in_std_ranges() {
// verify basic std::ranges functionality; noop if ranges not present
#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L
Matrix3f a = Matrix3f::Random();
int count = 0;
std::ranges::for_each(a.colwise(), [&count](auto&& col) { count += col.count(); });
VERIFY_IS_EQUAL(count, 9);
std::ranges::for_each(a.rowwise(), [&count](auto&& row) { count += row.count(); });
VERIFY_IS_EQUAL(count, 18);
#endif
}
EIGEN_DECLARE_TEST(vectorwiseop_ranges) { CALL_SUBTEST_1(vectorwiseop_use_in_std_ranges()); }