Category : argument-dependent-lookup

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( ..

Read more

The output of the following code is TA, but I don’t understand why. #include <iostream> #include <type_traits> struct A {}; template<typename T> void fun(T) { std::cout << "T"; } template<typename T> void caller(T t) { fun(A{}); fun(t); // the same output if I do `fun(std::move(t))`, so the value category seems not relevant here } void ..

Read more

I’m a little surprised that putting the variant’s alternative types into a sub-namespace seems to break the operator==: #include <variant> #include <iostream> namespace NS { namespace structs { struct A {}; struct B {}; } // namespace structs using V = std::variant<structs::A, structs::B>; bool operator==(const V& lhs, const V& rhs) { return lhs.index() == rhs.index(); ..

Read more