diff options
author | dmitrykobets-msft <89153909+dmitrykobets-msft@users.noreply.github.com> | 2022-04-29 00:58:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-29 00:58:25 +0300 |
commit | da01eb28dbb75bed11a51acff0f80ecedd622573 (patch) | |
tree | 1d7bcea1e7cffe12c4a6a412453a9b3c87223a46 | |
parent | d8c493c89fef3b1928803cf0af5a21630344ea7e (diff) |
Remove useless runtime checks in span implementation (#1029)
Both checks for Expects(ExtentType::size() != dynamic_extent); in storage_type are always useless. storage_type<ExtentType> is only ever created with ExtentType == extent_type<Extent>, where Extent has type std::size_t and is the extent of the span.
Looking at extent_type<std::size_t Ext>::size():
- if Ext != dynamic_extent, then size() always returns Ext, and therefore size() != dynamic_extent
- if Ext == dynamic_extent, then size() returns extent_type<dynamic_extent>::size_. size_ can only be set via one of two constructors:
- constexpr explicit extent_type(size_type size), which already does the check in question
- constexpr explicit extent_type(extent_type<Other> ext) : size_(ext.size()), which simply relies on the other extent's size() method
So there is no way for ExtentType::size() == dynamic_extent.
-rw-r--r-- | include/gsl/span | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/include/gsl/span b/include/gsl/span index 4413a4d..4d5bc7c 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -706,14 +706,11 @@ private: template <class OtherExtentType> constexpr storage_type(KnownNotNull data, OtherExtentType ext) : ExtentType(ext), data_(data.p) - { - Expects(ExtentType::size() != dynamic_extent); - } + {} template <class OtherExtentType> constexpr storage_type(pointer data, OtherExtentType ext) : ExtentType(ext), data_(data) { - Expects(ExtentType::size() != dynamic_extent); Expects(data || ExtentType::size() == 0); } |