Skip to content

Commit 988affc

Browse files
committed
[cppyy] Add test for conversion from std::vector to std::span
Test corresponding to commit: "[core] Avoid errors when using std::span backport from Python".
1 parent fd83373 commit 988affc

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

bindings/pyroot/cppyy/cppyy/test/test_stltypes.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# -*- coding: UTF-8 -*-
22
import py, sys, pytest, os
33
from pytest import mark, raises, skip
4-
from support import setup_make, pylong, pyunicode, maxvalue, ispypy
5-
4+
from support import setup_make, pylong, pyunicode, maxvalue, ispypy, no_root_errors
65

76
currpath = os.getcwd()
87
test_dct = currpath + "/libstltypesDict"
@@ -821,6 +820,30 @@ def test24_byte_vectors(self):
821820
for i, d in zip(range(-5, 5, 1), data):
822821
assert d == i
823822

823+
def test24_vector_to_span(self):
824+
"""Vectors should convert to std::span without errors"""
825+
826+
import cppyy
827+
828+
cppyy.cppdef("""
829+
double calc_cumsum(std::size_t n, std::span<double> v)
830+
{
831+
double sum = 0.0;
832+
for (int i = 0; i < n; i += 1) {
833+
sum += v[i];
834+
}
835+
return sum;
836+
}
837+
""")
838+
839+
l = list(range(4))
840+
v = cppyy.gbl.std.vector["double"](l)
841+
842+
with no_root_errors():
843+
result = cppyy.gbl.calc_cumsum(len(v), v)
844+
845+
assert result == sum(l)
846+
824847

825848
class TestSTLSTRING:
826849
def setup_class(cls):

0 commit comments

Comments
 (0)