Commit 865ee50
committed
[core] Avoid errors when using std::span backport from Python
The `vector<T> const&` constructor needs to be disabled if T is not a
const type, because we don't want to create `span<T>` from `vector<T>
const&`. The explicit disabling via SFINAE is necessary to this overload
is not accidentally taken by cppyy, resulting in the failure of
constructor wrapper code compilation.
Avoids errors like these when compiling ROOT with C++17:
```txt
In module 'Core':
/home/rembserj/code/root/root_install/include/ROOT/span.hxx:208:27: error: cannot initialize a member subobject of type 'pointer' (aka 'double *') with an rvalue of type 'const double *'
: length_(v.size()), data_(v.empty() ? nullptr : v.data())
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input_line_45:7:41: note: in instantiation of member function 'std::span<double>::span' requested here
(*(std::span<double>**)ret) = new std::span<double>((const std::vector<double, std::allocator<double> >&)*(const std::vector<double, std::allocator<double> >*)args[0]);
^
0
1
2
3
```
Reproducer:
```Python
import ROOT
ROOT.gInterpreter.Declare("""
void calc_cumsum(std::size_t n, std::span<double> v)
{
for (int i = 0; i < n; i += 1) {
std::cout << v[i] << std::endl;
}
}
""")
v = ROOT.std.vector["double"](list(range(4)))
ROOT.calc_cumsum(len(v), v)
```1 parent fd48a6d commit 865ee50
1 file changed
+7
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
207 | 214 | | |
208 | 215 | | |
209 | 216 | | |
| |||
0 commit comments