@@ -88,12 +88,20 @@ class MemView
8888 );
8989
9090 /* * Construct from a half open range of two pointers.
91- @note The byte at @start is in the view but the byte at @a end is not.
91+ @note The instance at @start is in the view but the instance at @a end is not.
9292 */
93- constexpr MemView (const void *start, // /< First byte in the view.
94- const void *end // /< First byte not in the view.
93+ template <typename T>
94+ constexpr MemView (T const *start, // /< First byte in the view.
95+ T const *end // /< First byte not in the view.
9596 );
9697
98+ /* * Construct from a half open range of two pointers.
99+ @note The instance at @start is in the view but the instance at @a end is not.
100+ */
101+ MemView (void const *start, // /< First byte in the view.
102+ void const *end // /< First byte not in the view.
103+ );
104+
97105 /* * Construct from nullptr.
98106 This implicitly makes the length 0.
99107 */
@@ -305,7 +313,8 @@ class StringView
305313 explicit StringView (const char *s);
306314
307315 // / Construct from @c MemView to reference the same view.
308- constexpr StringView (MemView const &that);
316+ // / @internal Can't be @c constexpr because @c static_cast of @c <void*> is not permitted.
317+ StringView (MemView const &that);
309318
310319 // / Construct from @c std::string, referencing the entire string contents.
311320 StringView (std::string const &str);
@@ -595,8 +604,13 @@ inline constexpr MemView::MemView()
595604inline constexpr MemView::MemView (void const *ptr, size_t n) : _ptr(ptr), _size(n)
596605{
597606}
598- inline constexpr MemView::MemView (void const *start, void const *end)
599- : _ptr(start), _size(static_cast <const char *>(end) - static_cast<const char *>(start))
607+ template <typename T> constexpr MemView::MemView (const T *start, const T *end) : _ptr(start), _size((end - start) * sizeof(T))
608+ {
609+ }
610+ // <void*> is magic, handle that specially.
611+ // No constexpr because the spec specifically forbids casting from <void*> to a typed pointer.
612+ inline MemView::MemView (void const *start, void const *end)
613+ : _ptr(start), _size(static_cast <const char *>(end) - static_cast<char const *>(start))
600614{
601615}
602616inline constexpr MemView::MemView (std::nullptr_t ) : _ptr(nullptr ), _size(0 )
@@ -820,7 +834,7 @@ inline StringView::StringView(const char *s) : _ptr(s), _size(strlen(s))
820834inline constexpr StringView::StringView (std::nullptr_t ) : _ptr(nullptr ), _size(0 )
821835{
822836}
823- inline constexpr StringView::StringView (MemView const &that) : _ptr(static_cast <const char *>(that.ptr())), _size(that.size())
837+ inline StringView::StringView (MemView const &that) : _ptr(static_cast <const char *>(that.ptr())), _size(that.size())
824838{
825839}
826840inline StringView::StringView (std::string const &str) : _ptr(str.data()), _size(str.size())
@@ -1055,24 +1069,22 @@ StringView::suffix(const char *p) const
10551069 return zret;
10561070}
10571071
1058- // gcc 4.9 - it considers passing this->find(...) to suffix() to be amibugous between the const char*
1059- // overload and the std::function<bool (char)>. This shows up on Debian 7, so let's try a cast to help out.
10601072inline auto
10611073StringView::suffix (char c) -> self
10621074{
1063- return this ->suffix (static_cast < const char *>( this ->find (c) ));
1075+ return this ->suffix (this ->find (c));
10641076}
10651077
10661078inline auto
10671079StringView::suffix (self delimiters) -> self
10681080{
1069- return this ->suffix (static_cast < const char *>( this ->find (delimiters) ));
1081+ return this ->suffix (this ->find (delimiters));
10701082}
10711083
10721084inline auto
10731085StringView::suffix (std::function<bool (char )> const &pred) -> self
10741086{
1075- return this ->suffix (static_cast < const char *>( this ->find (pred) ));
1087+ return this ->suffix (this ->find (pred));
10761088}
10771089
10781090inline StringView
0 commit comments