1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/*
Copyright 2019-2023 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) && !defined(BOOST_NO_CXX11_DECLTYPE)
#include <boost/core/span.hpp>
#include <boost/core/lightweight_test_trait.hpp>
template<class T>
struct range {
T* data() {
return 0;
}
const T* data() const {
return 0;
}
std::size_t size() const {
return 0;
}
};
struct buffer {
void* data() {
return 0;
}
const void* data() const {
return 0;
}
std::size_t size() const {
return 0;
}
};
struct base { };
struct derived
: base { };
void test_default()
{
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<
boost::span<int> >));
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<
boost::span<int, 0> >));
BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<
boost::span<int, 2> >));
}
void test_data_size()
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>,
int*, std::size_t>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>,
int*, std::size_t>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
int, std::size_t>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
const int*, std::size_t>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>,
derived*, std::size_t>));
}
void test_first_last()
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>,
int*, int*>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>,
int*, const int*>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>,
int*, int*>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
int, int*>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
const int*, int*>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>,
derived*, derived*>));
}
void test_array()
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>,
int(&)[4]>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int, 4>,
int(&)[4]>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 2>,
int(&)[4]>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 4>,
int(&)[2]>));
}
void test_std_array()
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>,
std::array<int, 4>&>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>,
std::array<int, 4>&>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int, 4>,
std::array<int, 4>&>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int,
4>, std::array<int, 4>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
std::array<const int, 4>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>,
std::array<derived, 4>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 2>,
std::array<int, 4>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 4>,
std::array<const int, 4>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base, 4>,
std::array<derived, 4>&>));
}
void test_const_std_array()
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>,
const std::array<int, 4> >));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int,
4>, const std::array<int, 4> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
const std::array<int, 4> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<const
base>, const std::array<derived, 4> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<const int,
2>, const std::array<int, 4> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 4>,
const std::array<int, 4> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<const
base, 4>, const std::array<derived, 4> >));
}
void test_range()
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>,
range<int>&>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>,
range<int>&>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>,
range<int> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
int*>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
range<int> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
const range<int>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>,
range<derived>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
buffer>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
const buffer&>));
}
void test_initializer_list()
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>,
std::initializer_list<int> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
std::initializer_list<int> >));
}
void test_span()
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>,
boost::span<int> >));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>,
boost::span<int, 4> >));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int, 4>,
boost::span<int> >));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int,
4>, boost::span<int, 4> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
boost::span<const int> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>,
boost::span<derived> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 2>,
boost::span<int, 4> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 4>,
boost::span<const int, 4> >));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base, 4>,
boost::span<derived, 4> >));
}
void test_copy()
{
BOOST_TEST_TRAIT_TRUE((std::is_copy_constructible<
boost::span<int> >));
BOOST_TEST_TRAIT_TRUE((std::is_copy_constructible<
boost::span<int, 4> >));
}
void test_assign()
{
BOOST_TEST_TRAIT_TRUE((std::is_copy_assignable<
boost::span<int> >));
BOOST_TEST_TRAIT_TRUE((std::is_copy_assignable<
boost::span<int, 4> >));
}
int main()
{
test_default();
test_data_size();
test_first_last();
test_array();
test_std_array();
test_const_std_array();
test_range();
test_initializer_list();
test_span();
test_copy();
test_assign();
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif
|