1/*
2Copyright 2019 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 <cstddef>
9#ifdef __cpp_lib_byte
10#include <boost/core/span.hpp>
11#include <boost/core/lightweight_test.hpp>
12
13void test_dynamic()
14{
15 int a[4];
16 boost::span<std::byte> s =
17 boost::as_writable_bytes(s: boost::span<int>(&a[0], 4));
18 BOOST_TEST_EQ(s.data(), reinterpret_cast<std::byte*>(&a[0]));
19 BOOST_TEST_EQ(s.size(), sizeof(int) * 4);
20}
21
22void test_static()
23{
24 int a[4];
25 boost::span<std::byte, sizeof(int) * 4> s =
26 boost::as_writable_bytes(s: boost::span<int, 4>(&a[0], 4));
27 BOOST_TEST_EQ(s.data(), reinterpret_cast<std::byte*>(&a[0]));
28 BOOST_TEST_EQ(s.size(), sizeof(int) * 4);
29}
30
31int main()
32{
33 test_dynamic();
34 test_static();
35 return boost::report_errors();
36}
37#else
38int main()
39{
40 return 0;
41}
42#endif
43

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