I’m having issues with ADL not finding hidden friends. I’m working on a c++20 codebase that is made to run on the latest versions of msvc however I’m moving it back a bit and getting it to compile with gcc 10.2.0 on arch linux. There are a few isolated places that are complaining about these ..
Category : argument-dependent-lookup
In the following code, the standalone component in the namespace S has its own definitions of Big and Small types, together with a split function to split one Big into a collection of the Smalls. S also provides another function, work, which makes use of split, and is meant to be used by S itself ..
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( ..
I am currently trying to get my feet wet with concepts. I tried to define a concept that could be implemented by users to adopt third-party data types for using them with my hypothetical library. template <class T> concept Initable = requires (T&t) { { init(t) }; }; // just for demonstration purposes, real concept ..
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 ..
Let’s say I am writing some generic algorithm in lib namespace that calls a customisation point my_func. First attempt is using ADL for my_func one of the user wants to specialise my_func for his type, which is an alias to std type. Surely define it in his namespace won’t work because ADL won’t work for ..
Consider the following example: namespace N { template<class> struct C { }; template<int, class T> void foo(C<T>); } template<class T> void bar(N::C<T> c) { foo<0>(c); } int main() { N::C<T> c; bar(c); } Both GCC and Clang fail to compile this code under C++17 standard (with -Werror), because (according to my understanding) in C++17 ADL ..
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(); ..
I was reading this blogpost about the trouble of customization points in C++17, so I wonder if there are any changes in C++20 regarding this. I am only concerned about language changes allowing me to write my library nicer, I presume there were no changes to std:: due to backward compatibility reasons. To make question ..
I know that my compiler in the example below will execute the function First::fun(), because of Argument-Dependent name Lookup (ADL)/Koenig lookup and in order to execute Second::fun() this needs to be explicitly called in the main function. #include <iostream> using namespace std; namespace First { enum Enum { FIRST }; void fun(First::Enum symbol) { cout ..
Recent Comments