view: prefer construction using explicit size over pointer arithmetic

This simplifies step through debugging on some containers.
This commit is contained in:
Danny Robson 2018-10-04 14:52:35 +10:00
parent 06d7d2840d
commit fdbe909fb8
2 changed files with 11 additions and 4 deletions

View File

@ -28,6 +28,13 @@ main (int, char**)
"string/pointer-view equality");
}
// construction from a std::array
{
std::array<std::byte,16> raw;
cruft::view obj { raw };
tap.expect_eq (obj.size (), raw.size (), "std::array construction size matches");
}
// comparator tests
{
static const struct {

View File

@ -172,14 +172,14 @@ namespace cruft {
//---------------------------------------------------------------------
template <typename CharT, typename Traits, typename Allocator>
view (std::basic_string<CharT,Traits,Allocator> &val):
view (std::data (val), std::data (val) + std::size (val))
view (std::data (val), std::size (val))
{ ; }
//---------------------------------------------------------------------
template <typename CharT, typename Traits, typename Allocator>
view (const std::basic_string<CharT,Traits,Allocator> &val):
view (std::data (val), std::data (val) + std::size (val))
view (std::data (val), std::size (val))
{ ; }
@ -193,14 +193,14 @@ namespace cruft {
//---------------------------------------------------------------------
template <typename ValueT, typename AllocatorT>
view (std::vector<ValueT,AllocatorT> &rhs):
view (std::data (rhs), std::data (rhs) + std::size (rhs))
view (std::data (rhs), std::size (rhs))
{ ; }
//---------------------------------------------------------------------
template <typename ValueT, std::size_t N>
view (std::array<ValueT,N> &rhs):
view (std::data (rhs), std::data (rhs) + std::size (rhs))
view (std::data (rhs), std::size (rhs))
{ ; }