87 lines · cpp
1#include <algorithm>2#include <functional>3#include <map>4#include <ranges>5#include <vector>6 7bool sort_less(int a, int b) {8 __builtin_printf("break here");9 return a < b;10}11 12bool ranges_sort_less(int a, int b) {13 __builtin_printf("break here");14 return a < b;15}16 17int view_transform(int a) {18 __builtin_printf("break here");19 return a * a;20}21 22void test_algorithms() {23 std::vector<int> vec{8, 1, 3, 2};24 25 // The internal frames for `std::sort` should be hidden26 std::sort(vec.begin(), vec.end(), sort_less);27 28 // The internal frames for `ranges::sort` should be hidden29 std::ranges::sort(vec.begin(), vec.end(), ranges_sort_less);30 31 // Same for views32 for (auto x : vec | std::ranges::views::transform(view_transform)) {33 // no-op34 }35}36 37void consume_number(int i) { __builtin_printf("break here"); }38 39int invoke_add(int i, int j) {40 __builtin_printf("break here");41 return i + j;42}43 44struct 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_;49};50 51void test_invoke() {52 // Invoke a void-returning function53 std::invoke(consume_number, -9);54 55 // Invoke a non-void-returning function56 std::invoke(invoke_add, 1, 10);57 58 // Invoke a member function59 const Callable foo(314159);60 std::invoke(&Callable::member_function, foo, 1);61 62 // Invoke a function object63 std::invoke(Callable(12), 18);64}65 66struct 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;72 }73};74 75void test_containers() {76 std::map<MyKey, int> map;77 map.emplace(MyKey{1}, 2);78 map.emplace(MyKey{2}, 3);79}80 81int main() {82 test_algorithms();83 test_invoke();84 test_containers();85 return 0;86}87