Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Oct 4, 2022
1 parent 208b2ea commit 72d78ba
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 50 deletions.
12 changes: 8 additions & 4 deletions core/include/detray/utils/ranges/empty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ template <typename value_t>
class empty_view : public detray::ranges::view_interface<empty_view<value_t>> {

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&){};

Expand All @@ -50,14 +51,17 @@ class empty_view : public detray::ranges::view_interface<empty_view<value_t>> {
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 {
Expand Down
10 changes: 4 additions & 6 deletions core/include/detray/utils/ranges/iota.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,21 @@ class iota_view : public detray::ranges::view_interface<iota_view<incr_t>> {
std::enable_if_t<not detray::detail::is_interval_v<deduced_incr_t>,
bool> = true>
DETRAY_HOST_DEVICE constexpr explicit iota_view(deduced_incr_t &&start)
: m_start{std::forward<deduced_incr_t>(start)},
m_end{std::forward<deduced_incr_t>(start) + 1} {}
: m_start{start}, m_end{start + 1} {}

/// Construct from an @param interval that defines start and end values.
template <typename interval_t,
std::enable_if_t<detray::detail::is_interval_v<interval_t>,
bool> = true>
DETRAY_HOST_DEVICE constexpr explicit iota_view(interval_t &&interval)
: m_start{detray::detail::get<0>(std::forward<interval_t>(interval))},
m_end{detray::detail::get<1>(std::forward<interval_t>(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 <typename deduced_incr_t>
DETRAY_HOST_DEVICE constexpr iota_view(deduced_incr_t &&start,
deduced_incr_t &&end)
: m_start{std::forward<deduced_incr_t>(start)},
m_end{std::forward<deduced_incr_t>(end) - 1} {}
: m_start{start}, m_end{end - 1} {}

/// Copy assignment operator
DETRAY_HOST_DEVICE
Expand Down
22 changes: 12 additions & 10 deletions core/include/detray/utils/ranges/join.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 <typename I = iterator_t,
Expand Down Expand Up @@ -330,7 +330,8 @@ struct join_iterator {
bool> = true>
DETRAY_HOST_DEVICE constexpr auto operator[](const dindex i) const
-> const value_type & {
int offset{static_cast<int>(i) - (m_iter - (*m_begins)[0])};
difference_type offset{static_cast<difference_type>(i) -
(m_iter - (*m_begins)[0])};
return *(*this + offset);
}

Expand All @@ -340,7 +341,8 @@ struct join_iterator {
bool> = true>
DETRAY_HOST_DEVICE constexpr auto operator[](const dindex i)
-> value_type & {
int offset{static_cast<int>(i) - (m_iter - (*m_begins)[0])};
difference_type offset{static_cast<difference_type>(i) -
(m_iter - (*m_begins)[0])};
return *(*this + offset);
}

Expand Down
2 changes: 0 additions & 2 deletions core/include/detray/utils/ranges/pick.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
50 changes: 22 additions & 28 deletions core/include/detray/utils/ranges/subrange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,48 @@ class subrange : public detray::ranges::view_interface<subrange<range_t>> {
public:
using iterator_t = typename detray::ranges::iterator_t<range_t>;
using const_iterator_t = typename detray::ranges::const_iterator_t<range_t>;
using range_size_t = typename detray::ranges::range_size_t<range_t>;
using difference_t = typename detray::ranges::range_difference_t<range_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<iterator_t>(start)},
m_end{std::forward<iterator_t>(end)} {}
template <typename deduced_itr_t,
std::enable_if_t<std::is_same_v<deduced_itr_t, iterator_t>,
bool> = true>
DETRAY_HOST_DEVICE constexpr subrange(deduced_itr_t &&start,
deduced_itr_t &&end)
: m_begin{std::forward<deduced_itr_t>(start)},
m_end{std::forward<deduced_itr_t>(end)} {}

/// Construct from a @param range.
template <
typename deduced_range_t,
std::enable_if_t<detray::ranges::range_v<deduced_range_t>, bool> = true>
DETRAY_HOST_DEVICE constexpr subrange(deduced_range_t &&range)
: m_begin{detray::ranges::begin(std::forward<deduced_range_t>(range))},
m_end{detray::ranges::end(std::forward<deduced_range_t>(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.
template <
typename deduced_range_t,
std::enable_if_t<detray::ranges::range_v<deduced_range_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<deduced_range_t>(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<deduced_range_t>,
std::enable_if_t<detray::ranges::range_v<deduced_range_t>, bool> = true,
typename = typename std::remove_reference_t<volume_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<deduced_range_t>>();

auto start =
detray::ranges::begin(std::forward<deduced_range_t>(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<deduced_range_t>(range),
vol.template range<value_t>()) {}

/// Construct from a @param range and an index range @param pos.
template <
Expand All @@ -84,12 +80,10 @@ class subrange : public detray::ranges::view_interface<subrange<range_t>> {
true>
DETRAY_HOST_DEVICE constexpr subrange(deduced_range_t &&range,
index_range_t &&pos)
: m_begin{detray::ranges::next(
detray::ranges::begin(std::forward<deduced_range_t>(range)),
detray::detail::get<0>(pos))},
m_end{detray::ranges::next(
detray::ranges::begin(std::forward<deduced_range_t>(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
Expand All @@ -105,7 +99,7 @@ class subrange : public detray::ranges::view_interface<subrange<range_t>> {

/// @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
Expand Down Expand Up @@ -133,7 +127,7 @@ template <
std::enable_if_t<detray::ranges::range_v<deduced_range_t>, bool> = true>
DETRAY_HOST_DEVICE subrange(
deduced_range_t &&range,
typename detray::ranges::range_size_t<deduced_range_t> pos)
typename detray::ranges::range_difference_t<deduced_range_t> pos)
->subrange<deduced_range_t>;

template <
Expand Down

0 comments on commit 72d78ba

Please sign in to comment.