1/*
2Copyright 2023 Glen Joseph Fernandes
3(glenjofe@gmail.com)
4
5Distributed under the Boost Software License, Version 1.0.
6(http://www.boost.org/LICENSE_1_0.txt)
7*/
8#include <boost/config.hpp>
9#if !defined(BOOST_NO_CXX11_CONSTEXPR) && !defined(BOOST_NO_CXX11_DECLTYPE)
10#include <boost/core/make_span.hpp>
11#include <boost/core/lightweight_test.hpp>
12
13template<class T>
14class range {
15public:
16 T* data() {
17 return &v_[0];
18 }
19
20 std::size_t size() const {
21 return 4;
22 }
23
24private:
25 T v_[4];
26};
27
28void test_data_size()
29{
30 int a[4];
31 boost::span<int> s = boost::make_span(f: &a[0], c: 4);
32 BOOST_TEST_EQ(s.data(), &a[0]);
33 BOOST_TEST_EQ(s.size(), 4);
34}
35
36void test_first_last()
37{
38 int a[4];
39 boost::span<int> s = boost::make_span(f: &a[0], l: &a[4]);
40 BOOST_TEST_EQ(s.data(), &a[0]);
41 BOOST_TEST_EQ(s.size(), 4);
42}
43
44void test_array()
45{
46 int a[4];
47 boost::span<int, 4> s = boost::make_span(a);
48 BOOST_TEST_EQ(s.data(), &a[0]);
49 BOOST_TEST_EQ(s.size(), 4);
50}
51
52void test_std_array()
53{
54 std::array<int, 4> a;
55 boost::span<int, 4> s = boost::make_span(a);
56 BOOST_TEST_EQ(s.data(), a.data());
57 BOOST_TEST_EQ(s.size(), a.size());
58}
59
60void test_const_std_array()
61{
62 const std::array<int, 4> a = std::array<int, 4>();
63 boost::span<const int> s = boost::make_span(a);
64 BOOST_TEST_EQ(s.data(), a.data());
65 BOOST_TEST_EQ(s.size(), a.size());
66}
67
68void test_range()
69{
70 range<int> c;
71 boost::span<int> s = boost::make_span(r&: c);
72 BOOST_TEST_EQ(s.data(), c.data());
73 BOOST_TEST_EQ(s.size(), c.size());
74}
75
76void test_initializer_list()
77{
78 std::initializer_list<int> l{1, 2};
79 boost::span<const int> s = boost::make_span(r&: l);
80 BOOST_TEST_EQ(s.data(), l.begin());
81 BOOST_TEST_EQ(s.size(), l.size());
82}
83
84int main()
85{
86 test_data_size();
87 test_first_last();
88 test_array();
89 test_std_array();
90 test_const_std_array();
91 test_range();
92 test_initializer_list();
93 return boost::report_errors();
94}
95#else
96int main()
97{
98 return 0;
99}
100#endif
101

source code of boost/libs/core/test/make_span_test.cpp