389 questions
2 votes
2 answers
147 views
Argument Dependent Lookup and global namespace
Following code snippet is taken from this presentation. It can be seen at 31:00. I couldn't understand the reason of ambiguity in this situation. Function 3 can be reachable via ADL naturally but why ...
1 vote
1 answer
139 views
Symbol lookup rules for :: global namespace operator
All this time, I thought that the global namespace resolution operator was optional, and for instances where a symbol refers to something in the global namespace, eg: void my_func() {} int main() { ...
2 votes
1 answer
76 views
How to make ADL work with overloaded functions across C++ modules?
I have a module A exporting a class template, that uses an overloaded function foo() dependent on the template's type argument: module; export module A; export void foo(bool a) {} export void foo(int ...
2 votes
1 answer
196 views
why using functor for implementing customization point, instead of simple function?
When you have a default implementation for some function and want to let users provide their own version for custom types, you have to do something like this: #include <cstdio> namespace Lib { ...
3 votes
2 answers
167 views
Force adl to not use function from specific namespace
I need to support a new type (OuterType) for libpqxx. This type is located in namespace partner, also namespace contains free function to_string(const OuterType&), which returns wrapper around ...
9 votes
1 answer
246 views
Why doesn't MSVC class' find friend function via ADL, preferring calling a lambda?
A cpp file and two headers ended up forming this "problematic" translation unit:² namespace na { struct Foo { friend int getFoo(Foo const&, int const&) { return 1; } }...
5 votes
3 answers
139 views
Adding an ostream inserter into std:: namespace
We have dozens of string-like classes spread across dozens of namespaces, but they each have a similar structure: namespace N::N1 { struct S1 { std::string_view sv() const; }; } We'd like to ...
3 votes
1 answer
117 views
why does 'using namespace' not take priority when in a namespace
This is a follow-up to no match for operator<<(std::ostream, ns::Type) when in the global namespace, combined with the namespace numerical_chars trick from https://stackoverflow.com/a/21389821/...
10 votes
1 answer
499 views
How to check at compile time for the existence of a global-scope function accepting given argument types?
What (I think) I need How can I define a type trait that checks whether, for a type T, the function ::foo(T) is declared? What I'm finding hard, is to have ::foo in SFINAE friendly way. For instance, ...
0 votes
0 answers
40 views
Why ADL does not kick in with unqualified swap() and std::size_t [duplicate]
Why wouldn't ADL kick in when I use unqualified swap() function with std::size_t passed arguments type? For example, I'd expect this to work: std::size_t v1, v2; swap(v1, v2); But it does not. On my ...
4 votes
1 answer
128 views
How to match the int type to a C++ concept requiring a valid function?
I'm trying out templates and concepts in C++. I wrote the following code. #include <iostream> #include <string> template <typename T> concept Printable = requires(T a) { { ...
4 votes
2 answers
92 views
Argument-dependent lookup for built in types vs user-defined types
My code: template <typename T> void func(T v) { func2(v); } struct S {}; void func2(int) {} void func2(S) {} int main() { func(1); // error here func(S{}); // OK } ...
0 votes
0 answers
130 views
Requires clause and friend injection
I am trying to have some fun with friend injection and requires clause but I got some trouble : template<int X> struct MaximumValue{}; template<int X> auto injectMaximumValue(MaximumValue&...
0 votes
1 answer
144 views
Why is the function with a std::initializer_list parameter not found despite trying to bring it into consideration with a 'using' declaration
I'm trying to bring a function into consideration with a using declaration: namespace n { struct S {}; bool equal(S a, S b, std::vector<int> = {1,2}) { return false; } } int main() { ...
0 votes
1 answer
85 views
How is the friend function accessed in the case of accessing private class member? [duplicate]
This is a tricky tactic to access a private member of class. But I can't get the point of declaration of friend get inside struct A_member? #include <iostream> struct A { private: int member; ...