1
0
forked from boostorg/core
Files
boost_core/test/as_writable_bytes_test.cpp

43 lines
917 B
C++
Raw Normal View History

2021-10-13 08:37:37 -04:00
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <cstddef>
#ifdef __cpp_lib_byte
2021-10-13 08:37:37 -04:00
#include <boost/core/span.hpp>
#include <boost/core/lightweight_test.hpp>
void test_dynamic()
{
int a[4];
boost::span<std::byte> s =
boost::as_writable_bytes(boost::span<int>(&a[0], 4));
BOOST_TEST_EQ(s.data(), reinterpret_cast<std::byte*>(&a[0]));
BOOST_TEST_EQ(s.size(), sizeof(int) * 4);
}
void test_static()
{
int a[4];
boost::span<std::byte, sizeof(int) * 4> s =
boost::as_writable_bytes(boost::span<int, 4>(&a[0], 4));
BOOST_TEST_EQ(s.data(), reinterpret_cast<std::byte*>(&a[0]));
BOOST_TEST_EQ(s.size(), sizeof(int) * 4);
}
int main()
{
test_dynamic();
test_static();
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif