argument-dependent-lookup Questions
1
Solved
The following very simple code won't compile
#include <vector>
#include <string>
namespace Foobar {
struct Test {
std::string f;
std::uint16_t uuid;
};
}
bool operator==(const F...
Slowpoke asked 20/7, 2018 at 17:44
2
Solved
Some time ago I read an article that explained several pitfalls of argument dependent lookup, but I cannot find it anymore. It was about gaining access to things that you should not have access to ...
Zomba asked 2/6, 2010 at 14:28
3
Solved
Let us define f, as a friend function of S, inside the declaration of S:
struct S
{
friend void f() {}
};
I cannot find a way to call f.
Is it true, then, that such an inline friend function c...
Endmost asked 12/7, 2018 at 11:31
1
Solved
Code #1
#include <iterator>
#include <algorithm>
#include <iostream>
#include <vector>
template <typename container>
void sort(typename container::iterator beginning...
Conjugal asked 10/4, 2018 at 8:3
2
Solved
Consider a simple example:
template <class T>
struct tag { };
int main() {
auto foo = [](auto x) -> decltype(bar(x)) { return {}; };
tag<int> bar(tag<int>);
bar(tag<int...
Caaba asked 2/2, 2018 at 15:55
3
As proper use of std::swap is:
using std::swap;
swap(a,b);
It is a bit verbose but it makes sure that if a,b have better swap defined it gets picked.
So now my question is why std::swap is not...
Preface asked 19/11, 2017 at 23:49
2
Solved
Why does the following code compile:
template<typename T>
void foo(T in) { bar(in); }
struct type{};
void bar(type) {}
int main() { foo(type()); }
When the following does not:
template&l...
Subserve asked 15/9, 2017 at 14:38
1
Solved
I was reading this blog post section, and I tried to play around with the snippet that was provided.
namespace N {
// 2
class A {
friend void f(A) {} // 1
};
}
If I understood correctly, the def...
Contortion asked 6/9, 2017 at 11:15
1
Solved
I'm using Visual Studio 2015.
Any idea why this code compiles:
#include <memory>
class Foo;
class Bar;
typedef std::pair<Foo*,std::weak_ptr<Bar>> Object;
typedef std::vector<...
Swanherd asked 4/7, 2017 at 10:12
1
Solved
namespace N {
class C {};
template<typename X>
char const * found(X && x) {
return "found";
}
template<typename, typename X>
char const * notfound(X && x) {
re...
Winonawinonah asked 12/6, 2017 at 1:2
1
Solved
I have an issue which is quite similar to this one.
In short, I have a magic method, which is noexcept if another method is noexcept.
The weird thing is that this "another method" has two overloa...
Darceydarci asked 3/5, 2017 at 15:29
2
Solved
I've spent some time trying to realize why my code doesn't compile and I've realized that in C++ Argument Dependent Lookup uses template typename arguments to determine name lookup scope.
#include...
Titanesque asked 19/4, 2017 at 10:21
2
Solved
How does find_type know where the function typemap is?
The argument it receives is not from that namespace, it's from the std namespace!
#include <type_traits>
#include <memory>
names...
Aphis asked 6/2, 2017 at 20:4
4
Solved
Imagine I'm writing some container template or something. And the time comes to specialize std::swap for it. As a good citizen, I'll enable ADL by doing something like this:
template <typename ...
Dulsea asked 3/10, 2011 at 13:51
1
Solved
After this question by utilizing ADL one can create a trait to answer if the passed type comes from our namespace:
#include <utility>
namespace helper
{
template <typename T, typename =...
Lehr asked 4/2, 2017 at 16:16
1
g++ fails to compile following code snippet:
namespace X {
enum En {A, B};
bool test(En e);
}
bool check() {
union {
struct {
X::En y:16;
X::En z:16;
} x;
int z;
} zz;
return test(zz.x...
Audiometer asked 1/8, 2016 at 19:3
2
Solved
This minimal program
template <typename X>
void foo (X x)
{
bar (x);
}
template <typename X>
void bar (X x)
{
}
int main ()
{
foo ([]{});
}
compiles with gcc (4.8.5 and 5.3) and ...
Dric asked 14/5, 2016 at 22:20
1
Solved
I just ran into some interesting behavior with argument-dependent lookup, which I do not fully understand:
#include <iostream>
namespace a {
struct Foo {
Foo(int v1, int v2) : v1(v1), v2(v...
Derwent asked 4/5, 2016 at 11:56
3
Solved
The following snippet:
#include <memory>
#include <utility>
namespace foo
{
template <typename T>
void swap(T& a, T& b)
{
T tmp = std::move(a);
a = std::move(b);
b...
Goth asked 25/4, 2016 at 20:32
1
Solved
In the following C++ example code, GCC 6 and Clang 3.8 disagree on what the correct behaviour is:
This contrived example "works" -- as in the test() function returns o.p in GCC. In clang, it calls...
Reorientation asked 19/4, 2016 at 15:11
1
Solved
Consider the following:
namespace N {
struct A { };
struct B {
B() { }
B(A const&) { }
friend void f(B const& ) { }
};
}
int main() {
f(N::B{}); // ok
f(N::A{}); // error
}
In ...
Boneset asked 16/3, 2016 at 0:58
3
For elegance, encapsulation and to exploit ADL (Argument Dependent Lookup) is common to define a function inside the namespace of the function argument.
Suppose I have two libraries in different n...
Fastening asked 8/1, 2016 at 11:26
2
Solved
Here is an example:
#include <string>
#include <algorithm>
#include <memory>
using std::string;
int main()
{
string str = "This is a string";
// ok: needn't using decl...
Connective asked 18/12, 2015 at 9:20
2
Solved
The following program
#include <algorithm>
#include <utility>
#include <memory>
namespace my_namespace
{
template<class T>
void swap(T& a, T& b)
{
T tmp = std::...
Brolly asked 3/12, 2015 at 20:39
3
Solved
Considering:
#include <cassert>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
int main() {
auto range = boost::irange(1, 4);
assert(boost::find(range,...
Rabia asked 3/11, 2015 at 16:8
© 2022 - 2024 — McMap. All rights reserved.