diff --git a/include/gsl/multi_span b/include/gsl/multi_span index dbca3a4..762a14a 100644 --- a/include/gsl/multi_span +++ b/include/gsl/multi_span @@ -279,42 +279,42 @@ namespace details struct BoundsRanges { using size_type = std::ptrdiff_t; - static const size_type Depth = 0; - static const size_type DynamicNum = 0; - static const size_type CurrentRange = 1; - static const size_type TotalSize = 1; + static constexpr size_type Depth = 0; + static constexpr size_type DynamicNum = 0; + static constexpr size_type CurrentRange = 1; + static constexpr size_type TotalSize = 1; // TODO : following signature is for work around VS bug template - BoundsRanges(const OtherRange&, bool /* firstLevel */) + constexpr BoundsRanges(const OtherRange&, bool /* firstLevel */) { } - BoundsRanges(const std::ptrdiff_t* const) {} - BoundsRanges() = default; + constexpr BoundsRanges(const std::ptrdiff_t* const) {} + constexpr BoundsRanges() = default; template - void serialize(T&) const + constexpr void serialize(T&) const { } template - size_type linearize(const T&) const + constexpr size_type linearize(const T&) const { return 0; } template - size_type contains(const T&) const + constexpr size_type contains(const T&) const { return -1; } - size_type elementNum(std::size_t) const GSL_NOEXCEPT { return 0; } + constexpr size_type elementNum(std::size_t) const GSL_NOEXCEPT { return 0; } - size_type totalSize() const GSL_NOEXCEPT { return TotalSize; } + constexpr size_type totalSize() const GSL_NOEXCEPT { return TotalSize; } - bool operator==(const BoundsRanges&) const GSL_NOEXCEPT { return true; } + constexpr bool operator==(const BoundsRanges&) const GSL_NOEXCEPT { return true; } }; template @@ -322,10 +322,10 @@ namespace details { using Base = BoundsRanges; using size_type = std::ptrdiff_t; - static const std::size_t Depth = Base::Depth + 1; - static const std::size_t DynamicNum = Base::DynamicNum + 1; - static const size_type CurrentRange = dynamic_range; - static const size_type TotalSize = dynamic_range; + static constexpr std::size_t Depth = Base::Depth + 1; + static constexpr std::size_t DynamicNum = Base::DynamicNum + 1; + static constexpr size_type CurrentRange = dynamic_range; + static constexpr size_type TotalSize = dynamic_range; private: size_type m_bound; @@ -373,9 +373,9 @@ namespace details size_type totalSize() const GSL_NOEXCEPT { return m_bound; } - size_type elementNum() const GSL_NOEXCEPT { return totalSize() / this->Base::totalSize(); } + constexpr size_type elementNum() const GSL_NOEXCEPT { return totalSize() / this->Base::totalSize(); } - size_type elementNum(std::size_t dim) const GSL_NOEXCEPT + constexpr size_type elementNum(std::size_t dim) const GSL_NOEXCEPT { if (dim > 0) return this->Base::elementNum(dim - 1); @@ -383,7 +383,7 @@ namespace details return elementNum(); } - bool operator==(const BoundsRanges& rhs) const GSL_NOEXCEPT + constexpr bool operator==(const BoundsRanges& rhs) const GSL_NOEXCEPT { return m_bound == rhs.m_bound && static_cast(*this) == static_cast(rhs); @@ -395,17 +395,17 @@ namespace details { using Base = BoundsRanges; using size_type = std::ptrdiff_t; - static const std::size_t Depth = Base::Depth + 1; - static const std::size_t DynamicNum = Base::DynamicNum; - static const size_type CurrentRange = CurRange; - static const size_type TotalSize = + static constexpr std::size_t Depth = Base::Depth + 1; + static constexpr std::size_t DynamicNum = Base::DynamicNum; + static constexpr size_type CurrentRange = CurRange; + static constexpr size_type TotalSize = Base::TotalSize == dynamic_range ? dynamic_range : CurrentRange * Base::TotalSize; - BoundsRanges(const std::ptrdiff_t* const arr) : Base(arr) {} - BoundsRanges() = default; + constexpr BoundsRanges(const std::ptrdiff_t* const arr) : Base(arr) {} + constexpr BoundsRanges() = default; template - BoundsRanges(const BoundsRanges& other, + constexpr BoundsRanges(const BoundsRanges& other, bool firstLevel = true) : Base(static_cast&>(other), false) { @@ -413,14 +413,14 @@ namespace details } template - void serialize(T& arr) const + constexpr void serialize(T& arr) const { arr[Dim] = elementNum(); this->Base::template serialize(arr); } template - size_type linearize(const T& arr) const + constexpr size_type linearize(const T& arr) const { Expects(arr[Dim] >= 0 && arr[Dim] < CurrentRange); // Index is out of range return this->Base::totalSize() * arr[Dim] + @@ -428,7 +428,7 @@ namespace details } template - size_type contains(const T& arr) const + constexpr size_type contains(const T& arr) const { if (arr[Dim] >= CurrentRange) return -1; const size_type last = this->Base::template contains(arr); @@ -436,11 +436,11 @@ namespace details return this->Base::totalSize() * arr[Dim] + last; } - size_type totalSize() const GSL_NOEXCEPT { return CurrentRange * this->Base::totalSize(); } + constexpr size_type totalSize() const GSL_NOEXCEPT { return CurrentRange * this->Base::totalSize(); } - size_type elementNum() const GSL_NOEXCEPT { return CurrentRange; } + constexpr size_type elementNum() const GSL_NOEXCEPT { return CurrentRange; } - size_type elementNum(std::size_t dim) const GSL_NOEXCEPT + constexpr size_type elementNum(std::size_t dim) const GSL_NOEXCEPT { if (dim > 0) return this->Base::elementNum(dim - 1); @@ -448,7 +448,7 @@ namespace details return elementNum(); } - bool operator==(const BoundsRanges& rhs) const GSL_NOEXCEPT + constexpr bool operator==(const BoundsRanges& rhs) const GSL_NOEXCEPT { return static_cast(*this) == static_cast(rhs); } @@ -467,31 +467,31 @@ namespace details struct TypeListIndexer { const TypeChain& obj_; - TypeListIndexer(const TypeChain& obj) : obj_(obj) {} + constexpr TypeListIndexer(const TypeChain& obj) : obj_(obj) {} template - const TypeChain& getObj(std::true_type) + constexpr const TypeChain& getObj(std::true_type) { return obj_; } template - auto getObj(std::false_type) + constexpr auto getObj(std::false_type) -> decltype(TypeListIndexer(static_cast(obj_)).template get()) { return TypeListIndexer(static_cast(obj_)).template get(); } template - auto get() -> decltype(getObj(std::integral_constant())) + constexpr auto get() -> decltype(getObj(std::integral_constant())) { return getObj(std::integral_constant()); } }; template - TypeListIndexer createTypeListIndexer(const TypeChain& obj) + constexpr TypeListIndexer createTypeListIndexer(const TypeChain& obj) { return TypeListIndexer(obj); }