Category : argument-dependent-lookup

Consider this example: #include <type_traits> class C { }; struct S { friend std::true_type f(C&) { return std::true_type(); } }; std::false_type f(C&); int main() { C c; return decltype(f(c))::value; } If I compile it, I get: <source>:10:17: error: functions that differ only in their return type cannot be overloaded However, if I comment out std::false_type ..

Read more

As per this post(https://quuxplusone.github.io/blog/2019/04/26/what-is-adl/), which says that: ADL considers only function arguments, not template arguments. Godbolt: namespace A { struct A { operator int(); }; struct X {}; template<class T> void f(int); } namespace B { template<class T> void f(); void test() { A::A a; f<A::X>(); // OK, ADL doesn’t consider A::f, calls B::f f<A::X>(a); ..

Read more

I am trying to understand how templates and friendship works in C++. So looking/trying out some examples by myself. One such example that i am unable to understand is given below: VERSION 1 #include <iostream> using namespace std; //template<typename T> void func4(); //template<typename T> class NAME; // template<typename T> std::ostream& operator<< (std::ostream&, NAME<T> const&); template<typename ..

Read more

Is it possible to provide a customized implementation within a user-defined namespace? For example, I want a user to implement customization points within a specific namespace, for example namespace custom. This is an example that works, but not the way I would like to have it: #include <iostream> namespace custom { // this does not ..

Read more

I’m trying to use a concept that applies to both built-in and user-defined types. In my setting, it is inconvenient to forward-declare certain functions (because the functions depend indirectly on the concepts causing my problem). My problem is that concepts don’t recognize functions that were not previously declared if those functions have arguments of built-in ..

Read more

Consider // https://godbolt.org/z/z5M9b9jzx #include <memory> #include <cassert> struct B {}; struct D : B {}; int main() { std::shared_ptr<B> b = std::make_shared<D>(); auto d = static_pointer_cast<D>(b); assert(d); } I’d’ve expected the unqualified call to static_pointer_cast to resolve to std::static_pointer_cast, because b, being a std::shared_ptr, should bring namespace std in using ADL. Why doesn’t it? I ..

Read more