diff options
author | John Ericson <git@JohnEricson.me> | 2025-08-22 22:24:56 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2025-08-22 22:25:03 -0400 |
commit | f23bac62f46fc296a4d0526ef54824d406c3756c (patch) | |
tree | cc1b97d5ba3616503e4605737cb270678f9b687f /libstdc++-v3/src | |
parent | 5b85364a6dd0bbfd3e26d3346b075a0819be7cd4 (diff) | |
download | gcc-master.zip gcc-master.tar.gz gcc-master.tar.bz2 |
The old C-style was cumbersome make making one responsible for manually
creating and passing in two parts a closure (separate function and
*_info class for closed-over variables).
With C++ lambdas, we can just:
- derive environment types implicitly
- have fewer stray static functions
Also thanks to templates we can
- make the return type polymorphic, to avoid casting pointee types.
Note that `struct spec_path` was *not* converted because it is used
multiple times. We could still convert to a lambda, but we would want to
put the for_each_path call with that lambda inside a separate function
anyways, to support the multiple callers. Unlike the other two
refactors, it is not clear that this one would make anything shorter.
Instead, I define the `operator()` explicitly. Keeping the explicit
struct gives us some nice "named arguments", versus the wrapper function
alternative, too.
gcc/ChangeLog:
* gcc.cc (for_each_path): templated, to make passing lambdas
possible/easy/safe, and to have a polymorphic return type.
(struct add_to_obstack_info): Deleted, lambda captures replace
it.
(add_to_obstack): Moved to lambda in build_search_list.
(build_search_list): Has above lambda now.
(struct file_at_path_info): Deleted, lambda captures replace
it.
(file_at_path): Moved to lambda in find_a_file.
(find_a_file): Has above lambda now.
(struct spec_path_info): Reamed to just struct spec_path.
(struct spec_path): New name.
(spec_path): Rnamed to spec_path::operator()
(spec_path::operator()): New name
(do_spec_1): Updated for_each_path call sites.
Signed-off-by: John Ericson <git@JohnEricson.me>
Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'libstdc++-v3/src')
0 files changed, 0 insertions, 0 deletions