Should operators be declared as non-member non-template friends

前端 未结 1 591
盖世英雄少女心
盖世英雄少女心 2021-01-03 20:04

Consider this question, which is about the following code not compiling:

std::vector a, b;
std::cout << (std::ref(a) < std::ref(b));


        
相关标签:
1条回答
  • 2021-01-03 20:36

    Given that, is there a reason to prefer the non-member function template that we currently have, or should this be considered a defect in the standard?

    The reason is if ADL could find out proper function or not. When such a search requires to extract the substituted template parameters from the type of given object and then substitute them many times into a templated parameter of the function template, ADL can't do this because of there are no reasons in the general case to prefer one way of template parameters binding to other. The non-member function template defined after but still in the namespace scope of that template (due to friend) excludes such an indeterminacy.

    0 讨论(0)
提交回复
热议问题