From 8a0794b722bd42d12c58295c69b659e79c73a903 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 24 Jul 2018 03:01:02 +0000 Subject: Implement . Reviewed as https://reviews.llvm.org/D49338 llvm-svn: 337804 --- .../std/containers/views/span.sub/last.pass.cpp | 136 +++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 libcxx/test/std/containers/views/span.sub/last.pass.cpp (limited to 'libcxx/test/std/containers/views/span.sub/last.pass.cpp') diff --git a/libcxx/test/std/containers/views/span.sub/last.pass.cpp b/libcxx/test/std/containers/views/span.sub/last.pass.cpp new file mode 100644 index 00000000000..4e378fe549e --- /dev/null +++ b/libcxx/test/std/containers/views/span.sub/last.pass.cpp @@ -0,0 +1,136 @@ +// -*- C++ -*- +//===------------------------------ span ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===---------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// + +// template +// constexpr span last() const; +// +// constexpr span last(index_type count) const; +// +// Requires: 0 <= Count && Count <= size(). + + +#include +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexprSpan(Span sp) +{ + LIBCPP_ASSERT((noexcept(sp.template last()))); + LIBCPP_ASSERT((noexcept(sp.last(Count)))); + auto s1 = sp.template last(); + auto s2 = sp.last(Count); + using S1 = decltype(s1); + using S2 = decltype(s2); + ASSERT_SAME_TYPE(typename Span::value_type, typename S1::value_type); + ASSERT_SAME_TYPE(typename Span::value_type, typename S2::value_type); + static_assert(S1::extent == Count, ""); + static_assert(S2::extent == std::dynamic_extent, ""); + return + s1.data() == s2.data() + && s1.size() == s2.size() + && std::equal(s1.begin(), s1.end(), sp.end() - Count); +} + + +template +void testRuntimeSpan(Span sp) +{ + LIBCPP_ASSERT((noexcept(sp.template last()))); + LIBCPP_ASSERT((noexcept(sp.last(Count)))); + auto s1 = sp.template last(); + auto s2 = sp.last(Count); + using S1 = decltype(s1); + using S2 = decltype(s2); + ASSERT_SAME_TYPE(typename Span::value_type, typename S1::value_type); + ASSERT_SAME_TYPE(typename Span::value_type, typename S2::value_type); + static_assert(S1::extent == Count, ""); + static_assert(S2::extent == std::dynamic_extent, ""); + assert(s1.data() == s2.data()); + assert(s1.size() == s2.size()); + assert(std::equal(s1.begin(), s1.end(), sp.end() - Count)); +} + + +constexpr int carr1[] = {1,2,3,4}; + int arr[] = {5,6,7}; +std::string sarr [] = { "ABC", "DEF", "GHI", "JKL", "MNO"}; + +int main () +{ + { + using Sp = std::span; + static_assert(testConstexprSpan(Sp{}), ""); + + static_assert(testConstexprSpan(Sp{carr1}), ""); + static_assert(testConstexprSpan(Sp{carr1}), ""); + static_assert(testConstexprSpan(Sp{carr1}), ""); + static_assert(testConstexprSpan(Sp{carr1}), ""); + static_assert(testConstexprSpan(Sp{carr1}), ""); + } + + { + using Sp = std::span; + + static_assert(testConstexprSpan(Sp{carr1}), ""); + static_assert(testConstexprSpan(Sp{carr1}), ""); + static_assert(testConstexprSpan(Sp{carr1}), ""); + static_assert(testConstexprSpan(Sp{carr1}), ""); + static_assert(testConstexprSpan(Sp{carr1}), ""); + } + + { + using Sp = std::span; + testRuntimeSpan(Sp{}); + + testRuntimeSpan(Sp{arr}); + testRuntimeSpan(Sp{arr}); + testRuntimeSpan(Sp{arr}); + testRuntimeSpan(Sp{arr}); + } + + { + using Sp = std::span; + + testRuntimeSpan(Sp{arr}); + testRuntimeSpan(Sp{arr}); + testRuntimeSpan(Sp{arr}); + testRuntimeSpan(Sp{arr}); + } + + { + using Sp = std::span; + testConstexprSpan(Sp{}); + + testRuntimeSpan(Sp{sarr}); + testRuntimeSpan(Sp{sarr}); + testRuntimeSpan(Sp{sarr}); + testRuntimeSpan(Sp{sarr}); + testRuntimeSpan(Sp{sarr}); + testRuntimeSpan(Sp{sarr}); + } + + { + using Sp = std::span; + + testRuntimeSpan(Sp{sarr}); + testRuntimeSpan(Sp{sarr}); + testRuntimeSpan(Sp{sarr}); + testRuntimeSpan(Sp{sarr}); + testRuntimeSpan(Sp{sarr}); + testRuntimeSpan(Sp{sarr}); + } +} -- cgit v1.2.3