public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107123] New: Size deduction for vector size in template fails
@ 2022-10-02 10:59 milasudril at gmail dot com
2022-10-03 18:42 ` [Bug c++/107123] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: milasudril at gmail dot com @ 2022-10-02 10:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107123
Bug ID: 107123
Summary: Size deduction for vector size in template fails
Product: gcc
Version: 12.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: milasudril at gmail dot com
Target Milestone: ---
Host: x86-64_linux_gnu
Target: x86-64_linux_gnu
I tried to write a generic inner product implementation, accepting vectorized
arguments:
```c++
#include <type_traits>
#include <cstddef>
template<class T>
concept arithmetic = std::is_arithmetic_v<T>;
template<arithmetic T, size_t N>
using native_vector [[gnu::vector_size(sizeof(T)*N)]] = T;
template<class T, size_t N>
auto inner_product(native_vector<T, N> a, native_vector<T, N> b)
{
auto const prod = a * b;
T ret{};
for(size_t k = 0; k != N; ++k)
{ ret += prod[k]; }
return ret;
}
auto test(native_vector<int, 4> a, native_vector<int, 4> b)
{
return inner_product(a, b);
}
```
Apparently, it is not possible to deduce N here:
```
<source>: In function 'auto test(native_vector<int, 4>, native_vector<int,
4>)':
<source>:23:25: error: no matching function for call to
'inner_product(native_vector<int, 4>&, native_vector<int, 4>&)'
23 | return inner_product(a, b);
| ~~~~~~~~~~~~~^~~~~~
<source>:11:6: note: candidate: 'template<class T, long unsigned int N> auto
inner_product(native_vector<T, N>, native_vector<T, N>)'
11 | auto inner_product(native_vector<T, N> a, native_vector<T, N> b)
| ^~~~~~~~~~~~~
<source>:11:6: note: template argument deduction/substitution failed:
<source>:23:25: note: couldn't deduce template parameter 'N'
23 | return inner_product(a, b);
```
I would appreciate if size deduction worked like for std::array:
```c++
#include <array>
template<class T, size_t N>
auto inner_product(std::array<T, N> a, std::array<T, N> b)
{
T ret{};
for(size_t k = 0; k != N; ++k)
{ ret += a[k]*b[k]; }
return ret;
}
auto test(std::array<int, 4> a, std::array<int, 4> b)
{
return inner_product(a, b); // N deduced to 4
}
```
The problem is present on gcc 10-trunk.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-03 19:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-02 10:59 [Bug c++/107123] New: Size deduction for vector size in template fails milasudril at gmail dot com
2022-10-03 18:42 ` [Bug c++/107123] " pinskia at gcc dot gnu.org
2022-10-03 18:42 ` pinskia at gcc dot gnu.org
2022-10-03 19:10 ` milasudril at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).