Skip to content

Commit

Permalink
adding back free functions for [c|cr][begin|end]
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Maples committed Apr 14, 2020
1 parent 7341c5d commit 9cb376c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/gsl/span_ext
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,34 @@ rend(const span<ElementType, Extent>& s) noexcept
return s.rend();
}

template <class ElementType, std::size_t Extent>
constexpr typename span<ElementType, Extent>::iterator
cbegin(const span<ElementType, Extent>& s) noexcept
{
return s.begin();
}

template <class ElementType, std::size_t Extent = dynamic_extent>
constexpr typename span<ElementType, Extent>::iterator
cend(const span<ElementType, Extent>& s) noexcept
{
return s.end();
}

template <class ElementType, std::size_t Extent>
constexpr typename span<ElementType, Extent>::reverse_iterator
crbegin(const span<ElementType, Extent>& s) noexcept
{
return s.rbegin();
}

template <class ElementType, std::size_t Extent>
constexpr typename span<ElementType, Extent>::reverse_iterator
crend(const span<ElementType, Extent>& s) noexcept
{
return s.rend();
}

} // namespace gsl

#endif // GSL_SPAN_EXT_H
12 changes: 12 additions & 0 deletions tests/span_ext_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,26 @@ TEST(span_ext_test, make_span_from_array_constructor)
EXPECT_TRUE((std::is_same<decltype(s.begin()), decltype(begin(s))>::value));
EXPECT_TRUE((std::is_same<decltype(s.end()), decltype(end(s))>::value));

EXPECT_TRUE((std::is_same<decltype(std::cbegin(s)), decltype(cbegin(s))>::value));
EXPECT_TRUE((std::is_same<decltype(std::cend(s)), decltype(cend(s))>::value));

EXPECT_TRUE((std::is_same<decltype(s.rbegin()), decltype(rbegin(s))>::value));
EXPECT_TRUE((std::is_same<decltype(s.rend()), decltype(rend(s))>::value));

EXPECT_TRUE((std::is_same<decltype(std::crbegin(s)), decltype(crbegin(s))>::value));
EXPECT_TRUE((std::is_same<decltype(std::crend(s)), decltype(crend(s))>::value));

EXPECT_TRUE(s.begin() == begin(s));
EXPECT_TRUE(s.end() == end(s));

EXPECT_TRUE(s.rbegin() == rbegin(s));
EXPECT_TRUE(s.rend() == rend(s));

EXPECT_TRUE(s.begin() == cbegin(s));
EXPECT_TRUE(s.end() == cend(s));

EXPECT_TRUE(s.rbegin() == crbegin(s));
EXPECT_TRUE(s.rend() == crend(s));
}

TEST(span_ext_test, ssize_free_function)
Expand Down

0 comments on commit 9cb376c

Please sign in to comment.