xref: /llvm-project/libcxx/test/std/utilities/function.objects/func.memfn/robust_against_adl.pass.cpp (revision 3c8e31e17b85c3d24ade9053d56c1998b4dd28cd)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <functional>
10 
11 #include <functional>
12 
13 #include "test_macros.h"
14 
15 struct Incomplete;
16 template<class T> struct Holder { T t; };
17 typedef Holder<Incomplete> *Ptr;
18 
19 struct A {
no_argsA20     Ptr no_args() const { return nullptr; }
one_argA21     Ptr one_arg(Ptr p) const { return p; }
one_arg_voidA22     void one_arg_void(Ptr) const { }
23 };
24 
main(int,char **)25 int main(int, char**)
26 {
27     A a;
28     A *pa = &a;
29     const A *cpa = &a;
30     Ptr x = nullptr;
31     const Ptr cx = nullptr;
32     std::mem_fn(&A::no_args)(a);
33     std::mem_fn(&A::no_args)(pa);
34     std::mem_fn(&A::no_args)(*cpa);
35     std::mem_fn(&A::no_args)(cpa);
36     std::mem_fn(&A::one_arg)(a, x);
37     std::mem_fn(&A::one_arg)(pa, x);
38     std::mem_fn(&A::one_arg)(a, cx);
39     std::mem_fn(&A::one_arg)(pa, cx);
40     std::mem_fn(&A::one_arg)(*cpa, x);
41     std::mem_fn(&A::one_arg)(cpa, x);
42     std::mem_fn(&A::one_arg)(*cpa, cx);
43     std::mem_fn(&A::one_arg)(cpa, cx);
44     std::mem_fn(&A::one_arg_void)(a, x);
45     std::mem_fn(&A::one_arg_void)(pa, x);
46     std::mem_fn(&A::one_arg_void)(a, cx);
47     std::mem_fn(&A::one_arg_void)(pa, cx);
48     std::mem_fn(&A::one_arg_void)(*cpa, x);
49     std::mem_fn(&A::one_arg_void)(cpa, x);
50     std::mem_fn(&A::one_arg_void)(*cpa, cx);
51     std::mem_fn(&A::one_arg_void)(cpa, cx);
52     return 0;
53 }
54