私はテンプレートクラスboo
のためにoperator|
を書こうとしていますが、テンプレートクラスがブースト範囲タイプ(例:boost::range::filter_range
- adlはローカルのものよりboost::range_detail::operator|(SinglePassRange& r, const replace_holder<T>)
を好む)のようになるまではすべてうまくいきます。なぜadlは 'boost :: range_detail :: operator |'を好むのですか?ローカル '演算子|'を介して?
adlがローカルネームスペース上のこの詳細なネームスペースをブーストからオーバーロードする方が好きな理由を説明できる人はいますか?
#include <vector>
#include <boost/range/adaptors.hpp>
namespace local
{
template<typename T>
struct boo {};
// this overload is not prefered when T is a boost::range::xxx_range
template<typename T, typename U>
auto operator|(boo<T>, U)
{
return false;
}
void finds_local_operator_overload()
{
std::vector<int> xs;
// works like expected and calls local::operator|
auto f = boo<decltype(xs)>{} | xs;
}
void prefers_boost_range_detail_replaced_operator_overload_instead_of_local_operator()
{
std::vector<int> xs;
// compiler error because it tries to call 'boost::range_detail::operator|'
auto filtered = xs | boost::adaptors::filtered([](auto &&x){ return x % 2; });
auto f = boo<decltype(filtered)>{} | xs;
}
}
打ち鳴らすエラー(ほぼ同じMSVCレポート):ADLのルールによれば
/xxx/../../thirdparty/boost/1.60.0/dist/boost/range/value_type.hpp:26:70: error: no type named 'type' in
'boost::range_iterator<local::boo<boost::range_detail::filtered_range<(lambda at
/xxx/Tests.cpp:221:49), std::vector<int, std::allocator<int> > > >, void>'
struct range_value : iterator_value< typename range_iterator<T>::type >
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/xxx/../../thirdparty/boost/1.60.0/dist/boost/range/adaptor/replaced.hpp:122:40: note: in instantiation of template class
'boost::range_value<local::boo<boost::range_detail::filtered_range<(lambda at
/xxx/Tests.cpp:221:49), std::vector<int, std::allocator<int> > > > >' requested
here
BOOST_DEDUCED_TYPENAME range_value<SinglePassRange>::type>& f)
^
/xxx/Tests.cpp:222:37: note: while substituting deduced template arguments into
function template 'operator|' [with SinglePassRange = local::boo<boost::range_detail::filtered_range<(lambda at
/xxx/Tests.cpp:221:49), std::vector<int, std::allocator<int> > > >]
auto f = boo<decltype(filtered)>{} | xs;
オペレータを考慮する必要があります。私はブーストのものがあなたのものよりも専門的だと思う。 – Jarod42
'boost :: range_detail :: replace_holder'テンプレート関数はなぜ考慮されていますか? boost名前空間を開く引数はありません。 ブースト空間からのテンプレート 'T'のみが存在します。 それを考慮する十分な理由がある場合、なぜ他のブースト範囲ホルダーテンプレート関数も考慮されていないのですか? – TimW