mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 12:11:04 +01:00
Support ranges with overloaded const/non-const begin and end. (#7627)
If we find an overload set containing mulitple methods, discard any non-const methods and try again. This allows libc++'s `std::vector` to be iterated with range-based for.
This commit is contained in:
@@ -90,6 +90,33 @@ fn Test() {
|
||||
Core.AssertIsRange(Cpp.ConstRangeWithSentinel);
|
||||
}
|
||||
|
||||
// --- methods_overloaded.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Core library "cpp_range_for_iterate";
|
||||
|
||||
import Cpp inline '''c++
|
||||
struct OverloadedRange {
|
||||
struct ConstIterator {};
|
||||
struct ConstSentinel {};
|
||||
struct Iterator {};
|
||||
struct Sentinel {};
|
||||
|
||||
auto begin() -> Iterator;
|
||||
auto end() -> Sentinel;
|
||||
auto begin() const -> ConstIterator;
|
||||
auto end() const -> ConstSentinel;
|
||||
};
|
||||
''';
|
||||
|
||||
fn Test() {
|
||||
Core.AssertIsRange(Cpp.OverloadedRange);
|
||||
// We should pick the const overloads.
|
||||
let _: Core.CppRangeForIterate where
|
||||
.Iterator = Cpp.OverloadedRange.ConstIterator and
|
||||
.Sentinel = Cpp.OverloadedRange.ConstSentinel = Cpp.OverloadedRange;
|
||||
}
|
||||
|
||||
// --- adl_return_same_types.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user