summaryrefslogtreecommitdiff
path: root/include/safe-ctype.h
diff options
context:
space:
mode:
authorPedro Alves <pedro@palves.net>2022-08-05 16:12:56 +0200
committerTom de Vries <tdevries@suse.de>2022-08-05 16:12:56 +0200
commit377c3a9c91785d5df5c0d96121160e6210204cc0 (patch)
tree9e161fd592615e7cdc45d2d137926d6453236e90 /include/safe-ctype.h
parent5ee285ca3e5cca998c76ca1c92927008849ff00e (diff)
Introduce gdb::make_function_view
This adds gdb::make_function_view, which lets you create a function view from a callable without specifying the function_view's template parameter. For example, this: auto lambda = [&] (int) { ... }; auto fv = gdb::make_function_view (lambda); instead of: auto lambda = [&] (int) { ... }; gdb::function_view<void (int)> fv = lambda; It is particularly useful if you have a template function with an optional function_view parameter, whose type depends on the function's template parameters. Like: template<typename T> void my_function (T v, gdb::function_view<void(T)> callback = nullptr); For such a function, the type of the callback argument you pass must already be a function_view. I.e., this wouldn't compile: auto lambda = [&] (int) { ... }; my_function (1, lambda); With gdb::make_function_view, you can write the call like so: auto lambda = [&] (int) { ... }; my_function (1, gdb::make_function_view (lambda)); Unit tests included. Tested by building with GCC 9.4, Clang 10, and GCC 4.8.5, on x86_64 GNU/Linux, and running the unit tests. Change-Id: I5c4b3b4455ed6f0d8878cf1be189bea3ee63f626
Diffstat (limited to 'include/safe-ctype.h')
0 files changed, 0 insertions, 0 deletions