If I have a structure the overloads begin
, end
, etc. like the following:
#include <array>
template<typename T>
struct Array10
{
private:
std::array<T, 10> m_array;
public:
constexpr auto begin()
{
return std::begin(m_array); // #1
}
constexpr auto end()
{
return std::end(m_array);
}
// cbegin, cend, rbegin, rend, crbegin, crend
};
int main()
{
Array10<int> arr;
std::fill(
std::begin(arr), // #2
std::end(arr),
0);
}
then I understand why I have to use std::begin
instead of begin
in #1(because that's the closest scope begin
is defined in), but I don't understand why i have to use it in #2.
My first guess would be because Array10
is in the same namespace as main
, but putting it into its own namespace didn't solve the problem.
So: Why does ADL not find std::begin
in main
(#2)?
question from:
https://stackoverflow.com/questions/65925200/adl-not-working-outside-even-of-structure 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…