[clang] Add tracking source deduction guide for the explicitly-written
[llvm-project.git] / lldb / test / API / lang / cpp / libcxx-internals-recognizer / main.cpp
blob870301b0970439d1ec8ced66c2a07cfcf04565c9
1 #include <algorithm>
2 #include <functional>
3 #include <map>
4 #include <ranges>
5 #include <vector>
7 bool sort_less(int a, int b) {
8 __builtin_printf("break here");
9 return a < b;
12 bool ranges_sort_less(int a, int b) {
13 __builtin_printf("break here");
14 return a < b;
17 int view_transform(int a) {
18 __builtin_printf("break here");
19 return a * a;
22 void test_algorithms() {
23 std::vector<int> vec{8, 1, 3, 2};
25 // The internal frames for `std::sort` should be hidden
26 std::sort(vec.begin(), vec.end(), sort_less);
28 // The internal frames for `ranges::sort` should be hidden
29 std::ranges::sort(vec.begin(), vec.end(), ranges_sort_less);
31 // Same for views
32 for (auto x : vec | std::ranges::views::transform(view_transform)) {
33 // no-op
37 void consume_number(int i) { __builtin_printf("break here"); }
39 int invoke_add(int i, int j) {
40 __builtin_printf("break here");
41 return i + j;
44 struct Callable {
45 Callable(int num) : num_(num) {}
46 void operator()(int i) const { __builtin_printf("break here"); }
47 void member_function(int i) const { __builtin_printf("break here"); }
48 int num_;
51 void test_invoke() {
52 // Invoke a void-returning function
53 std::invoke(consume_number, -9);
55 // Invoke a non-void-returning function
56 std::invoke(invoke_add, 1, 10);
58 // Invoke a member function
59 const Callable foo(314159);
60 std::invoke(&Callable::member_function, foo, 1);
62 // Invoke a function object
63 std::invoke(Callable(12), 18);
66 struct MyKey {
67 int x;
68 bool operator==(const MyKey &) const = default;
69 bool operator<(const MyKey &other) const {
70 __builtin_printf("break here");
71 return x < other.x;
75 void test_containers() {
76 std::map<MyKey, int> map;
77 map.emplace(MyKey{1}, 2);
78 map.emplace(MyKey{2}, 3);
81 int main() {
82 test_algorithms();
83 test_invoke();
84 test_containers();
85 return 0;