From 9cb376c0508475c8aa8be015ef266558232f9583 Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Tue, 14 Apr 2020 16:57:12 -0700 Subject: [PATCH] adding back free functions for [c|cr][begin|end] --- include/gsl/span_ext | 28 ++++++++++++++++++++++++++++ tests/span_ext_tests.cpp | 12 ++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/gsl/span_ext b/include/gsl/span_ext index 0f8c4c9..1d375fd 100644 --- a/include/gsl/span_ext +++ b/include/gsl/span_ext @@ -165,6 +165,34 @@ rend(const span& s) noexcept return s.rend(); } +template +constexpr typename span::iterator +cbegin(const span& s) noexcept +{ + return s.begin(); +} + +template +constexpr typename span::iterator +cend(const span& s) noexcept +{ + return s.end(); +} + +template +constexpr typename span::reverse_iterator +crbegin(const span& s) noexcept +{ + return s.rbegin(); +} + +template +constexpr typename span::reverse_iterator +crend(const span& s) noexcept +{ + return s.rend(); +} + } // namespace gsl #endif // GSL_SPAN_EXT_H diff --git a/tests/span_ext_tests.cpp b/tests/span_ext_tests.cpp index 74aba3e..d413e03 100644 --- a/tests/span_ext_tests.cpp +++ b/tests/span_ext_tests.cpp @@ -208,14 +208,26 @@ TEST(span_ext_test, make_span_from_array_constructor) EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::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)