我尝试使用 Range-V3 库(用于 MSVC),但由于缺乏文档,我不明白如何做一件事。
std::map<int, std::wstring> ss = { {1,L"1"}, {2,L"2"}, {3,L"3"} };
auto rng = ss | ranges::view::reverse | ranges::view::values;
auto it = ranges::find_if(rng, [](auto&&x) {return x == L"2"; });
if (it != rng.end()) {
assert(it.base()->first == 2); // this does not compile
}
我从中得到find_if
什么?这是迭代器吗?我想获得一个基本元素的迭代器,即ss
映射中的值。
这是我得到的错误:
1>d:\sources\ranges_test\ranges_test.cpp(11): error C2819: type 'ranges::v3::basic_iterator<ranges::v3::adaptor_cursor<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,ranges::v3::reverse_view<ranges::v3::sized_range<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>>>::adaptor<true>>,ranges::v3::adaptor_cursor<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,ranges::v3::reverse_view<ranges::v3::sized_range<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>>>::adaptor<true>>>' does not have an overloaded member 'operator ->'
1> with
1> [
1> _Kty=int,
1> _Ty=std::wstring
1> ]
1>d:\sources\fingrad\dev.fingrad\src\vc\lib\range\v3\utility\basic_iterator.hpp(656): note: see declaration of 'ranges::v3::basic_iterator<ranges::v3::adaptor_cursor<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,ranges::v3::reverse_view<ranges::v3::sized_range<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>>>::adaptor<true>>,ranges::v3::adaptor_cursor<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,ranges::v3::reverse_view<ranges::v3::sized_range<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>>>::adaptor<true>>>'
1> with
1> [
1> _Kty=int,
1> _Ty=std::wstring
1> ]
1>d:\sources\ranges_test\ranges_test.cpp(11): note: did you intend to use '.' instead?
1>d:\sources\ranges_test\ranges_test.cpp(11): error C2039: 'first': is not a member of 'ranges::v3::basic_iterator<ranges::v3::adaptor_cursor<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,ranges::v3::reverse_view<ranges::v3::sized_range<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>>>::adaptor<true>>,ranges::v3::adaptor_cursor<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,ranges::v3::reverse_view<ranges::v3::sized_range<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>>>::adaptor<true>>>'
1> with
1> [
1> _Kty=int,
1> _Ty=std::wstring
1> ]
1>d:\sources\fingrad\dev.fingrad\src\vc\lib\range\v3\utility\basic_iterator.hpp(656): note: see declaration of 'ranges::v3::basic_iterator<ranges::v3::adaptor_cursor<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,ranges::v3::reverse_view<ranges::v3::sized_range<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>>>::adaptor<true>>,ranges::v3::adaptor_cursor<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,ranges::v3::reverse_view<ranges::v3::sized_range<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>>>::adaptor<true>>>'
1> with
1> [
1> _Kty=int,
1> _Ty=std::wstring
1> ]