diff options
author | Pedro Alves <pedro@palves.net> | 2022-08-05 16:12:56 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2022-08-05 16:12:56 +0200 |
commit | 377c3a9c91785d5df5c0d96121160e6210204cc0 (patch) | |
tree | 9e161fd592615e7cdc45d2d137926d6453236e90 /libiberty | |
parent | 5ee285ca3e5cca998c76ca1c92927008849ff00e (diff) | |
download | gdb-377c3a9c91785d5df5c0d96121160e6210204cc0.zip gdb-377c3a9c91785d5df5c0d96121160e6210204cc0.tar.gz gdb-377c3a9c91785d5df5c0d96121160e6210204cc0.tar.bz2 |
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 'libiberty')
0 files changed, 0 insertions, 0 deletions