我尝试使用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
map中得到值。
这是我得到的错误:
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> ]
答案 0 :(得分:3)
这看起来像范围V3的MSVC implementation中的错误 1 (或者更确切地说是缺失的特征)。一个简单的解决方法是用以下代码替换您的代码:
assert((*it.base()).first == 2);
这应该有效,因为basic_iterator
operator->
的重载是operator->
而$posts = $this->Posts->find()
->select()
->join([
'a' => [
'table' => 'animals',
'type' => 'INNER',
'conditions' =>'a.id = Posts.animal_id'
],
'u' => [
'table' => 'users',
'type' => 'INNER',
'conditions' =>'u.id = a.user_id'
]
])
->where(['u.id' => '2',
'a.id'=> $jqueryanimalvalue //here is null
]);
没有。{/ p>
1 如果您查看operator*
的MSVC来源,您会注意到$posts = $this->Posts->find()
->select()
->join([
'a' => [
'table' => 'animals',
'type' => 'INNER',
'conditions' => [
'a.id = Posts.animal_id',
'a.id IS ' . $jqueryanimalvalue // if it is null
]
],
'u' => [
'table' => 'users',
'type' => 'INNER',
'conditions' => [
'u.id = a.user_id',
'u.id' => '2'
]
]
]);
没有重载,而原始范围中有一个-v3 { {3}}