[PATCH v3 1/3] gdbserver: use 'gdb::function_view' in 'find_*' and 'for_each_*'

Simon Marchi simark@simark.ca
Fri Oct 18 17:34:03 GMT 2024



On 2024-10-18 11:20, Stephan Rohr wrote:
> Remove the templated versions of 'find_thread', 'for_each_thread' and
> 'find_thread_in_random' and replace the template function argument with
> 'gdb::function_view'.

It would perhaps be good to say why we do that change.  It's a bit
subjective, but in my opinion function_view is easier to work with than
templates.  The function_view type documents well the types of the
parameters taken by the callback and its return type.  The error
messages are less cryptic, when there are errors.

> -template <typename Func>
> -static process_info *
> -find_process (Func func)
> -{
> -  std::list<process_info *>::iterator next, cur = all_processes.begin ();
> -
> -  while (cur != all_processes.end ())
> -    {
> -      next = cur;
> -      next++;
> -
> -      if (func (*cur))
> -	return *cur;
> -
> -      cur = next;
> -    }
> -
> -  return NULL;
> -}
> +process_info *
> +find_process (gdb::function_view<bool (process_info *)> func);

Remove line break after return type.

Otherwise, this patch LGTM:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon


More information about the Gdb-patches mailing list