Skip to content

Commit

Permalink
Added test case to check if a span can be constructed automatically w…
Browse files Browse the repository at this point in the history
…hen passing a vector as input parameter.
  • Loading branch information
S-Dafarra committed Dec 9, 2021
1 parent d8a450e commit 708827b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/SpanUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,20 @@ TEST_CASE("from_std_array_const_constructor")
}
}

size_t foo(Span<const int> input)
{
return input.size();
}

TEST_CASE("from_container_constructor")
{
std::vector<int> v = {1, 2, 3};
const std::vector<int> cv = v;

size_t sizeAfterDeducton = foo(cv);

REQUIRE(sizeAfterDeducton == v.size());

{
Span<int> s{v};
REQUIRE((s.size() == static_cast<std::ptrdiff_t>(v.size()) && s.data() == v.data()));
Expand Down Expand Up @@ -428,6 +437,14 @@ TEST_CASE("from_container_constructor")
auto cs = make_span(cv);
REQUIRE((cs.size() == static_cast<std::ptrdiff_t>(cv.size()) && cs.data() == cv.data()));
}

{
auto lambdaSize = [](Span<const int> input){return input.size();};

size_t sizeAfterDeducton = lambdaSize(cv);

REQUIRE(sizeAfterDeducton == v.size());
}
}

TEST_CASE("from_convertible_span_constructor")
Expand Down

0 comments on commit 708827b

Please sign in to comment.