diff --git a/include/array_view.h b/include/array_view.h index a2ea49f..0145799 100644 --- a/include/array_view.h +++ b/include/array_view.h @@ -74,6 +74,13 @@ namespace details { static const SizeType max_value = std::numeric_limits::max(); }; + + + template + class are_integral : public std::integral_constant {}; + + template + class are_integral : public std::integral_constant::value && are_integral::value> {}; } template @@ -99,7 +106,7 @@ public: std::copy(values, values + Rank, elems); } - template> + template::value, typename Dummy = std::enable_if_t> constexpr index(Ts... ds) noexcept : elems{ static_cast(ds)... } {} @@ -227,142 +234,6 @@ private: value_type elems[Rank] = {}; }; -template -class index<1, ValueType> -{ - template - friend class index; - -public: - static const size_t rank = 1; - using value_type = std::remove_reference_t; - using reference = std::add_lvalue_reference_t; - using const_reference = std::add_lvalue_reference_t>; - - constexpr index() noexcept : value(0) - {} - - constexpr index(value_type e) noexcept : value(e) - {} - - constexpr index(const value_type(&values)[1]) noexcept : index(values[0]) - {} - - constexpr index(const index &) noexcept = default; - - template ::max_value <= details::SizeTypeTraits::max_value), - typename Other = std::enable_if_t>> - constexpr index(const index<1, OtherValueType>& other) noexcept - { - value = static_cast(other.value); - } - - template ::max_value > details::SizeTypeTraits::max_value), - typename Other = std::enable_if_t>> - constexpr index(const index<1, OtherValueType>& other, void* ptr=0) noexcept - { - fail_fast_assert(other.value <= static_cast(details::SizeTypeTraits::max_value)); - value = static_cast(other.value); - } - - // Preconditions: component_idx < 1 - constexpr reference operator[](value_type component_idx) noexcept - { - fail_fast_assert(component_idx == 0, "Component index must be less than rank"); - (void)(component_idx); - return value; - } - // Preconditions: component_idx < 1 - constexpr const_reference operator[](value_type component_idx) const noexcept - { - fail_fast_assert(component_idx == 0, "Component index must be less than rank"); - (void)(component_idx); - return value; - } - constexpr bool operator==(const index& rhs) const noexcept - { - return value == rhs.value; - } - constexpr bool operator!=(const index& rhs) const noexcept - { - return !(*this == rhs); - } - constexpr index operator+() const noexcept - { - return *this; - } - constexpr index operator-() const noexcept - { - return index(-value); - } - constexpr index operator+(const index& rhs) const noexcept - { - return index(value + rhs.value); - } - constexpr index operator-(const index& rhs) const noexcept - { - return index(value - rhs.value); - } - constexpr index& operator+=(const index& rhs) noexcept - { - value += rhs.value; - return *this; - } - constexpr index& operator-=(const index& rhs) noexcept - { - value -= rhs.value; - return *this; - } - constexpr index& operator++() noexcept - { - ++value; - return *this; - } - constexpr index operator++(int) noexcept - { - index ret = *this; - ++(*this); - return ret; - } - constexpr index& operator--() noexcept - { - --value; - return *this; - } - constexpr index operator--(int) noexcept - { - index ret = *this; - --(*this); - return ret; - } - constexpr index operator*(value_type v) const noexcept - { - return index(value * v); - } - constexpr index operator/(value_type v) const noexcept - { - return index(value / v); - } - constexpr index& operator*=(value_type v) noexcept - { - value *= v; - return *this; - } - constexpr index& operator/=(value_type v) noexcept - { - value /= v; - return *this; - } - friend constexpr index operator*(value_type v, const index& rhs) noexcept - { - return{ rhs * v }; - } -private: - value_type value; -}; - #ifndef _MSC_VER struct static_bounds_dynamic_range_t @@ -1128,132 +999,6 @@ private: std::remove_const_t curr; }; -template -class bounds_iterator> : public std::iterator> -{ - using Base = std::iterator>; - -public: - using typename Base::reference; - using typename Base::pointer; - using typename Base::difference_type; - using typename Base::value_type; - using index_type = value_type; - using index_size_type = typename index_type::value_type; - - template - constexpr explicit bounds_iterator(const Bounds&, value_type curr) noexcept - : curr(std::move(curr)) - {} - - constexpr reference operator*() const noexcept - { - return curr; - } - - constexpr pointer operator->() const noexcept - { - &curr; - } - - constexpr bounds_iterator& operator++() noexcept - { - ++curr; - return *this; - } - - constexpr bounds_iterator operator++(int) noexcept - { - auto ret = *this; - ++(*this); - return ret; - } - - constexpr bounds_iterator& operator--() noexcept - { - curr--; - return *this; - } - - constexpr bounds_iterator operator--(int) noexcept - { - auto ret = *this; - --(*this); - return ret; - } - - constexpr bounds_iterator operator+(difference_type n) const noexcept - { - bounds_iterator ret{ *this }; - return ret += n; - } - - constexpr bounds_iterator& operator+=(difference_type n) noexcept - { - curr += n; - return *this; - } - - constexpr bounds_iterator operator-(difference_type n) const noexcept - { - bounds_iterator ret{ *this }; - return ret -= n; - } - - constexpr bounds_iterator& operator-=(difference_type n) noexcept - { - return *this += -n; - } - - constexpr difference_type operator-(const bounds_iterator& rhs) const noexcept - { - return curr[0] - rhs.curr[0]; - } - - constexpr reference operator[](difference_type n) const noexcept - { - return curr + n; - } - - constexpr bool operator==(const bounds_iterator& rhs) const noexcept - { - return curr == rhs.curr; - } - - constexpr bool operator!=(const bounds_iterator& rhs) const noexcept - { - return !(*this == rhs); - } - - constexpr bool operator<(const bounds_iterator& rhs) const noexcept - { - return curr[0] < rhs.curr[0]; - } - - constexpr bool operator<=(const bounds_iterator& rhs) const noexcept - { - return !(rhs < *this); - } - - constexpr bool operator>(const bounds_iterator& rhs) const noexcept - { - return rhs < *this; - } - - constexpr bool operator>=(const bounds_iterator& rhs) const noexcept - { - return !(rhs > *this); - } - - constexpr void swap(bounds_iterator& rhs) noexcept - { - std::swap(curr, rhs.curr); - } - -private: - std::remove_const_t curr; -}; - template bounds_iterator operator+(typename bounds_iterator::difference_type n, const bounds_iterator& rhs) noexcept {