core
core copied to clipboard
Add checks for extent compatability in span range constructor
Based on discussion in https://github.com/boostorg/core/pull/179 / @pdimov suggestion.
few notes
- This will break some current code that does not exibit UB, for example constructing
spanof extent 3 fromboost::arrayof size 4. As this is not allowed forstd::arrayI presumed same logic should follow for other ranges. - I did not know a nicer C++11 way to produce an error message if extents do not match, so I used this mechanism with conversion of argument to resolve ambiguity
- regarding formatting: I found no clang-format file in repo so I did my best to do what seems right
- as for tests: I was trying to follow existing practices
- lmk if comments are too extensive
- if
span_default_constructed_sizeworks correctly maybe it should be moved to separate header if we think it will be useful in more places - I did not add runtime checks with
BOOST_ASSERT, I prefer to do that in separate PR - I did not add checks for
max_size, that may be useful for some fixed buffer types, e.g. static_string - for
std::spanavailability in test I used C++23 macro(I presume all C++23 compilers have all C++20 headers) since it is easier than to check for span header, if you prefer I can switch to specific span check - I used
boost::arrayas a nice range type, I know core can not depend on almost anything, but I presumed it is fine in tests a I think boost array does not depend on core, if not let me know so I make a simple test type. -
b2 cxxstd=03 testfails, not sure if that is fine as C++11 is new minimal Boost version