diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2025-02-09 00:51:00 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2025-02-10 11:17:23 -0500 |
commit | 9044044c27c3619a18f58c8c235250264cd95a7e (patch) | |
tree | 31047d51cd7b89de6b86688ca3e6e83a926eab3c /gdb/doc | |
parent | a4242dc3f5fa34a1686237c8b40a29d5fad1bcea (diff) | |
download | binutils-9044044c27c3619a18f58c8c235250264cd95a7e.zip binutils-9044044c27c3619a18f58c8c235250264cd95a7e.tar.gz binutils-9044044c27c3619a18f58c8c235250264cd95a7e.tar.bz2 |
gdbsupport: add gdb::make_array_view overload to create from an array
I think this overload will be useful for the following reasons.
Consider a templated function like this:
template <typename T>
void func(gdb::array_view<T> view) {}
Trying to pass an array to this function doesn't work, as template
argument deduction fails:
test.c:698:8: error: no matching function for call to ‘func(int [12])’
698 | func (array);
| ~~~~~^~~~~~~
test.c:686:6: note: candidate: ‘template<class T> void func(gdb::array_view<U>)’
686 | void func(gdb::array_view<T> view) {}
| ^~~~
test.c:686:6: note: template argument deduction/substitution failed:
test.c:698:8: note: mismatched types ‘gdb::array_view<U>’ and ‘int*’
698 | func (array);
| ~~~~~^~~~~~~
Similarly, trying to compare a view with an array doesn't work. This:
int array[12];
gdb::array_view<int> view;
if (view == array) {}
... fails with:
test.c:698:8: error: no matching function for call to ‘func(int [12])’
698 | func (array);
| ~~~~~^~~~~~~
test.c:686:6: note: candidate: ‘template<class T> void func(gdb::array_view<U>)’
686 | void func(gdb::array_view<T> view) {}
| ^~~~
test.c:686:6: note: template argument deduction/substitution failed:
test.c:698:8: note: mismatched types ‘gdb::array_view<U>’ and ‘int*’
698 | func (array);
| ~~~~~^~~~~~~
With this new overload, we can do:
func (gdb::make_array_view (array));
and
if (view == gdb::make_array_view (array)) {}
This is not ideal, I wish that omitting `gdb::make_array_view` would
just work, but at least it allows creating an array view and have the
element type automatically deduced from the array type.
If someone knows how to make these cases "just work", I would be happy
to know how.
Change-Id: I6a71919d2d5a385e6826801d53f5071b470fef5f
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/doc')
0 files changed, 0 insertions, 0 deletions