view: prefer construction using explicit size over pointer arithmetic
This simplifies step through debugging on some containers.
This commit is contained in:
parent
06d7d2840d
commit
fdbe909fb8
@ -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 {
|
||||
|
8
view.hpp
8
view.hpp
@ -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))
|
||||
{ ; }
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user