]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Introduce gdb::make_function_view users/palves/make_function_view
authorPedro Alves <pedro@palves.net>
Thu, 21 Jul 2022 20:55:37 +0000 (21:55 +0100)
committerPedro Alves <pedro@palves.net>
Fri, 22 Jul 2022 13:18:49 +0000 (14:18 +0100)
commit37c2487312d2997bed16343f642ecb5e83bac979
tree29d0d11be9ee7eff3e28246a14758db1a30cc758
parent6577f365ebdee7dda71cb996efa29d3714cbccd0
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
gdb/unittests/function-view-selftests.c
gdbsupport/function-view.h