mirror of
https://github.com/boostorg/core.git
synced 2025-11-29 22:00:17 +01:00
Add asserts to span
This commit is contained in:
@@ -409,6 +409,7 @@ run span_test.cpp ;
|
||||
run span_types_test.cpp ;
|
||||
run span_constructible_test.cpp ;
|
||||
run span_deduction_guide_test.cpp ;
|
||||
run span_constexpr_test.cpp ;
|
||||
run as_bytes_test.cpp ;
|
||||
run as_writable_bytes_test.cpp ;
|
||||
compile span_boost_begin_test.cpp ;
|
||||
|
||||
72
test/span_constexpr_test.cpp
Normal file
72
test/span_constexpr_test.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
Copyright 2025 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_CONSTEXPR)
|
||||
#include <boost/core/span.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
constexpr const int array[4]{ 5, 10, 15, 20 };
|
||||
|
||||
void test_first()
|
||||
{
|
||||
constexpr boost::span<const int> s =
|
||||
boost::span<const int>(array, 4).first(2);
|
||||
BOOST_TEST_EQ(s.data(), &array[0]);
|
||||
BOOST_TEST_EQ(s.size(), 2);
|
||||
}
|
||||
|
||||
void test_last()
|
||||
{
|
||||
constexpr boost::span<const int> s =
|
||||
boost::span<const int>(array, 4).last(2);
|
||||
BOOST_TEST_EQ(s.data(), &array[2]);
|
||||
BOOST_TEST_EQ(s.size(), 2);
|
||||
}
|
||||
|
||||
void test_subspan()
|
||||
{
|
||||
constexpr boost::span<const int> s =
|
||||
boost::span<const int>(array, 4).subspan(1, 2);
|
||||
BOOST_TEST_EQ(s.data(), &array[1]);
|
||||
BOOST_TEST_EQ(s.size(), 2);
|
||||
}
|
||||
|
||||
void test_index()
|
||||
{
|
||||
constexpr const int i = boost::span<const int>(array, 4)[1];
|
||||
BOOST_TEST_EQ(i, 10);
|
||||
}
|
||||
|
||||
void test_front()
|
||||
{
|
||||
constexpr const int i = boost::span<const int>(array, 4).front();
|
||||
BOOST_TEST_EQ(i, 5);
|
||||
}
|
||||
|
||||
void test_back()
|
||||
{
|
||||
constexpr const int i = boost::span<const int>(array, 4).back();
|
||||
BOOST_TEST_EQ(i, 20);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_first();
|
||||
test_last();
|
||||
test_subspan();
|
||||
test_index();
|
||||
test_front();
|
||||
test_back();
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user