1 // -*- C++ -*-
2 //===------------------------------ span ---------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===---------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 
11 // <span>
12 
13 // template<size_t Count>
14 //  constexpr span<element_type, Count> last() const;
15 //
16 // constexpr span<element_type, dynamic_extent> last(size_type count) const;
17 //
18 //  Requires: Count <= size().
19 
20 #include <span>
21 
22 #include <cstddef>
23 
24 #include "test_macros.h"
25 
26 constexpr int carr[] = {1, 2, 3, 4};
27 
main(int,char **)28 int main(int, char**) {
29   std::span<const int, 4> sp(carr);
30 
31   //  Count too large
32   {
33     [[maybe_unused]] auto s1 = sp.last<5>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Count out of range in span::last()"}}
34   }
35 
36   //  Count numeric_limits
37   {
38     [[maybe_unused]] auto s1 = sp.last<std::size_t(-1)>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Count out of range in span::last()"}}
39   }
40 
41   return 0;
42 }
43