Implement std::ranges view support in matchers#4893
Open
ozars wants to merge 1 commit intogoogle:mainfrom
Open
Implement std::ranges view support in matchers#4893ozars wants to merge 1 commit intogoogle:mainfrom
std::ranges view support in matchers#4893ozars wants to merge 1 commit intogoogle:mainfrom
Conversation
- Add feature flags for `std::ranges` and `std::views::as_const` detection. - Extend `StlContainerView` with a `std::ranges::view` specialization. - Introduce `internal::ValueType` to deduce element/value type for both STL containers and ranges, while keeping backward-compatibility for the existing behavior. - Update container matchers to use `internal::ValueType` instead of assuming nested `value_type`. - Add coverage for common matchers against `std::ranges` views (e.g. `ElementsAre`, `ElementsAreArray`, `Contains`, `Pointwise`, `UnorderedPointwise`, `Pointee`). - Resolves google#3403. - Resolves google#4512. - Resolves google#4534. Tested: On x86_64-pc-linux-gnu, with gcc 15.2.1 and clang 21.1.6, with libstdc++ for both, with build types Debug and Release, with C++ standards 17, 20 and 23. Ad-hoc test script is given below. ```bash #!/bin/bash set -o errexit set -o nounset set -o pipefail function check() { local cc="$1" local cxx="$2" local build_type="$3" local std="$4" local build_dir="build_${cc}_${build_type}_${std}" echo -e "\033[1m" echo "=== Building with $cc/$cxx, type=$build_type, std=$std ===" echo -e "\033[0m" rm -rf "$build_dir" mkdir -p "$build_dir" CC="$cc" CXX="$cxx" \ cmake \ -S . \ -B "$build_dir" \ -G "Ninja" \ -Dgtest_build_tests=ON \ -Dgmock_build_tests=ON \ -DCMAKE_BUILD_TYPE="$build_type" \ -DCMAKE_CXX_STANDARD="$std" \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON cmake --build "$build_dir" -- -j$(nproc) cmake --build "$build_dir" --target test } check "gcc" "g++" "Debug" "17" check "gcc" "g++" "Release" "17" check "gcc" "g++" "Debug" "20" check "gcc" "g++" "Release" "20" check "gcc" "g++" "Debug" "23" check "gcc" "g++" "Release" "23" check "clang" "clang++" "Debug" "17" check "clang" "clang++" "Release" "17" check "clang" "clang++" "Debug" "20" check "clang" "clang++" "Release" "20" check "clang" "clang++" "Debug" "23" check "clang" "clang++" "Release" "23" ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
std::rangesandstd::views::as_constdetection.StlContainerViewwith astd::ranges::viewspecialization.internal::ValueTypeto deduce element/value type for both STL containers and ranges, while keeping backward-compatibility for the existing behavior.internal::ValueTypeinstead of assuming nestedvalue_type.std::rangesviews (e.g.ElementsAre,ElementsAreArray,Contains,Pointwise,UnorderedPointwise,Pointee).Tested: On x86_64-pc-linux-gnu, with gcc 15.2.1 and clang 21.1.6, with libstdc++ for both, with build types Debug and Release, with C++ standards 17, 20 and 23.
Ad-hoc test script is given below.