391 questions
-2
votes
0
answers
84
views
ADL rules differences between gcc 11.4 and gcc 12.1 [duplicate]
I have the following code, where a library defines a few types in the lib namespace including a wrap type template. It also defines the operator+ for the template but checks the operator+ on the ...
17
votes
1
answer
648
views
Should a friend function in a namespace different from the class be found by argument-dependent lookup?
Consider
struct A;
namespace ns { int f(A&&); }
struct A {
friend int ns::f(A&&);
};
int x = f(A{});
GCC trunk translates the last line into a call to ns::f(A&&) in C++20 ...
2
votes
2
answers
158
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
142
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
77
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
198
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
169
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
251
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
121
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
506
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
129
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
95
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
132
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&...