From 72d78bae7ad81432e23a4b2e24f4b81d40c6fac3 Mon Sep 17 00:00:00 2001 From: Joana Niermann Date: Tue, 4 Oct 2022 16:36:25 +0200 Subject: [PATCH] cleanup --- core/include/detray/utils/ranges/empty.hpp | 12 +++-- core/include/detray/utils/ranges/iota.hpp | 10 ++-- core/include/detray/utils/ranges/join.hpp | 22 ++++---- core/include/detray/utils/ranges/pick.hpp | 2 - core/include/detray/utils/ranges/subrange.hpp | 50 ++++++++----------- 5 files changed, 46 insertions(+), 50 deletions(-) diff --git a/core/include/detray/utils/ranges/empty.hpp b/core/include/detray/utils/ranges/empty.hpp index 8c69ae7cf5..d5774c2dd5 100644 --- a/core/include/detray/utils/ranges/empty.hpp +++ b/core/include/detray/utils/ranges/empty.hpp @@ -21,12 +21,13 @@ template class empty_view : public detray::ranges::view_interface> { public: + /// Iterator category: bidirectional using iterator_t = value_t*; /// Default constructor constexpr empty_view() = default; - /// Copy assignment operator + /// Copy assignment operator - does nothing DETRAY_HOST_DEVICE empty_view& operator=(const empty_view&){}; @@ -50,14 +51,17 @@ class empty_view : public detray::ranges::view_interface> { DETRAY_HOST_DEVICE static constexpr bool empty() noexcept { return true; } + /// No value contained in view + /// @{ DETRAY_HOST_DEVICE - constexpr value_t front() const noexcept { return {}; } + constexpr value_t front() const noexcept = delete; DETRAY_HOST_DEVICE - constexpr value_t back() const noexcept { return {}; } + constexpr value_t back() const noexcept = delete; DETRAY_HOST_DEVICE - constexpr value_t operator[](const dindex) const noexcept { return {}; } + constexpr value_t operator[](const dindex) const noexcept = delete; + /// @} }; namespace views { diff --git a/core/include/detray/utils/ranges/iota.hpp b/core/include/detray/utils/ranges/iota.hpp index 3cb669ad5f..96d8a14ba8 100644 --- a/core/include/detray/utils/ranges/iota.hpp +++ b/core/include/detray/utils/ranges/iota.hpp @@ -91,23 +91,21 @@ class iota_view : public detray::ranges::view_interface> { std::enable_if_t, bool> = true> DETRAY_HOST_DEVICE constexpr explicit iota_view(deduced_incr_t &&start) - : m_start{std::forward(start)}, - m_end{std::forward(start) + 1} {} + : m_start{start}, m_end{start + 1} {} /// Construct from an @param interval that defines start and end values. template , bool> = true> DETRAY_HOST_DEVICE constexpr explicit iota_view(interval_t &&interval) - : m_start{detray::detail::get<0>(std::forward(interval))}, - m_end{detray::detail::get<1>(std::forward(interval))} {} + : m_start{detray::detail::get<0>(interval)}, + m_end{detray::detail::get<1>(interval)} {} /// Construct from a @param start start and @param end value. template DETRAY_HOST_DEVICE constexpr iota_view(deduced_incr_t &&start, deduced_incr_t &&end) - : m_start{std::forward(start)}, - m_end{std::forward(end) - 1} {} + : m_start{start}, m_end{end - 1} {} /// Copy assignment operator DETRAY_HOST_DEVICE diff --git a/core/include/detray/utils/ranges/join.hpp b/core/include/detray/utils/ranges/join.hpp index cdb371ec8b..20e9b835ed 100644 --- a/core/include/detray/utils/ranges/join.hpp +++ b/core/include/detray/utils/ranges/join.hpp @@ -24,7 +24,7 @@ struct join_iterator; } -/// @brief Range adaptor that joins together different ranges of the same type. +/// @brief Range adaptor that joins different ranges of the same type (static) /// /// @see https://en.cppreference.com/w/cpp/ranges/join_view /// @@ -148,7 +148,7 @@ namespace detail { /// @brief Sequentially iterate through multiple ranges of the same type. /// /// Once the sentinel of one range is reached, set the current iterator to the -/// next ranges 'begin'. +/// next ranges 'begin' (or 'end' if decrementing) /// /// @tparam iterator_coll_t type of iterator collection of ranges to be joined. /// Can contain const iterators. @@ -187,14 +187,14 @@ struct join_iterator { /// @returns true if it points to the same value. DETRAY_HOST_DEVICE constexpr bool operator==( const join_iterator &rhs) const { - return m_iter == rhs.m_iter; + return (m_iter == rhs.m_iter); } /// @returns false if it points to the same value (usually the global /// sentinel of the join). DETRAY_HOST_DEVICE constexpr bool operator!=( const join_iterator &rhs) const { - return m_iter != rhs.m_iter; + return (m_iter != rhs.m_iter); } /// Increment current iterator and check for switch between ranges. @@ -229,12 +229,12 @@ struct join_iterator { } /// @returns the single value that the iterator points to. - DETRAY_HOST_DEVICE auto operator*() -> value_type & { return *m_iter; } + DETRAY_HOST_DEVICE + constexpr auto operator*() -> value_type & { return *m_iter; } /// @returns the single value that the iterator points to - const - DETRAY_HOST_DEVICE constexpr auto operator*() const -> const value_type & { - return *m_iter; - } + DETRAY_HOST_DEVICE + constexpr auto operator*() const -> const value_type & { return *m_iter; } /// @returns an iterator advanced by @param j through the join. template = true> DETRAY_HOST_DEVICE constexpr auto operator[](const dindex i) const -> const value_type & { - int offset{static_cast(i) - (m_iter - (*m_begins)[0])}; + difference_type offset{static_cast(i) - + (m_iter - (*m_begins)[0])}; return *(*this + offset); } @@ -340,7 +341,8 @@ struct join_iterator { bool> = true> DETRAY_HOST_DEVICE constexpr auto operator[](const dindex i) -> value_type & { - int offset{static_cast(i) - (m_iter - (*m_begins)[0])}; + difference_type offset{static_cast(i) - + (m_iter - (*m_begins)[0])}; return *(*this + offset); } diff --git a/core/include/detray/utils/ranges/pick.hpp b/core/include/detray/utils/ranges/pick.hpp index 9831411241..ab90698616 100644 --- a/core/include/detray/utils/ranges/pick.hpp +++ b/core/include/detray/utils/ranges/pick.hpp @@ -131,7 +131,6 @@ class pick_view : public detray::ranges::view_interface< -> iterator & { detray::ranges::advance(m_seq_iter, j); m_range_begin += *m_seq_iter; - return *this; } @@ -175,7 +174,6 @@ class pick_view : public detray::ranges::view_interface< m_range_end = other.m_range_end; m_seq_begin = other.m_seq_begin; m_seq_end = other.m_seq_end; - return *this; } diff --git a/core/include/detray/utils/ranges/subrange.hpp b/core/include/detray/utils/ranges/subrange.hpp index dfc9c0568c..f9552fab2d 100644 --- a/core/include/detray/utils/ranges/subrange.hpp +++ b/core/include/detray/utils/ranges/subrange.hpp @@ -29,23 +29,27 @@ class subrange : public detray::ranges::view_interface> { public: using iterator_t = typename detray::ranges::iterator_t; using const_iterator_t = typename detray::ranges::const_iterator_t; - using range_size_t = typename detray::ranges::range_size_t; + using difference_t = typename detray::ranges::range_difference_t; /// Default constructor subrange() = default; /// Construct from an @param start and @param end iterator pair. - DETRAY_HOST_DEVICE constexpr subrange(iterator_t &&start, iterator_t &&end) - : m_begin{std::forward(start)}, - m_end{std::forward(end)} {} + template , + bool> = true> + DETRAY_HOST_DEVICE constexpr subrange(deduced_itr_t &&start, + deduced_itr_t &&end) + : m_begin{std::forward(start)}, + m_end{std::forward(end)} {} /// Construct from a @param range. template < typename deduced_range_t, std::enable_if_t, bool> = true> DETRAY_HOST_DEVICE constexpr subrange(deduced_range_t &&range) - : m_begin{detray::ranges::begin(std::forward(range))}, - m_end{detray::ranges::end(std::forward(range))} {} + : m_begin{detray::ranges::begin(range)}, + m_end{detray::ranges::end(range)} {} /// Construct from a @param range and starting position @param pos. Used /// as an overload when only a single position is needed. @@ -53,28 +57,20 @@ class subrange : public detray::ranges::view_interface> { typename deduced_range_t, std::enable_if_t, bool> = true> DETRAY_HOST_DEVICE constexpr subrange(deduced_range_t &&range, - range_size_t pos) - : m_begin{detray::ranges::next( - detray::ranges::begin(std::forward(range)), - pos)}, + difference_t pos) + : m_begin{detray::ranges::next(detray::ranges::begin(range), pos)}, m_end{detray::ranges::next(m_begin)} {} /// Construct from a @param range and an index range provided by a volume /// @param vol. template < typename deduced_range_t, typename volume_t, + typename value_t = detray::ranges::range_value_t, std::enable_if_t, bool> = true, typename = typename std::remove_reference_t::volume_def> - DETRAY_HOST_DEVICE subrange(deduced_range_t &&range, const volume_t &vol) { - const dindex_range r = vol.template range< - typename detray::ranges::range_value_t>(); - - auto start = - detray::ranges::begin(std::forward(range)); - - m_begin = start + detray::detail::get<0>(r); - m_end = start + detray::detail::get<1>(r); - } + DETRAY_HOST_DEVICE subrange(deduced_range_t &&range, const volume_t &vol) + : subrange(std::forward(range), + vol.template range()) {} /// Construct from a @param range and an index range @param pos. template < @@ -84,12 +80,10 @@ class subrange : public detray::ranges::view_interface> { true> DETRAY_HOST_DEVICE constexpr subrange(deduced_range_t &&range, index_range_t &&pos) - : m_begin{detray::ranges::next( - detray::ranges::begin(std::forward(range)), - detray::detail::get<0>(pos))}, - m_end{detray::ranges::next( - detray::ranges::begin(std::forward(range)), - detray::detail::get<1>(pos))} {} + : m_begin{detray::ranges::next(detray::ranges::begin(range), + detray::detail::get<0>(pos))}, + m_end{detray::ranges::next(detray::ranges::begin(range), + detray::detail::get<1>(pos))} {} /// Copy assignment operator DETRAY_HOST_DEVICE @@ -105,7 +99,7 @@ class subrange : public detray::ranges::view_interface> { /// @return start position of the range - const DETRAY_HOST_DEVICE - constexpr auto begin() const -> const_iterator_t { return m_begin; } + constexpr auto begin() const -> iterator_t { return m_begin; } /// @return sentinel of the range. DETRAY_HOST_DEVICE @@ -133,7 +127,7 @@ template < std::enable_if_t, bool> = true> DETRAY_HOST_DEVICE subrange( deduced_range_t &&range, - typename detray::ranges::range_size_t pos) + typename detray::ranges::range_difference_t pos) ->subrange; template <