Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 95 additions & 2 deletions include/RAJA/index/RangeSegment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,20 @@ using common_type_t = typename common_type<Ts...>::type;

} // namespace detail

/*!
* \brief Function to make a TypedRangeSegment for the interval [0, end)
*
* \return a newly constructed TypedRangeSegment where the
* value_type is equivilent to the common type of
* @begin and @end. If there is no common type, then
* a compiler error will be produced.
Comment on lines +537 to +540
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update comment

*/
template <typename EndT>
RAJA_HOST_DEVICE TypedRangeSegment<EndT> make_range(EndT&& end)
{
return {0, end};
}

/*!
* \brief Function to make a TypedRangeSegment for the interval [begin, end)
*
Expand All @@ -548,6 +562,29 @@ RAJA_HOST_DEVICE TypedRangeSegment<Common> make_range(BeginT&& begin,
return {begin, end};
}

/*!
* \brief Function to make a TypedRangeStride Segment for the interval
* [begin, end) with given stride
*
* \return a newly constructed TypedRangeStrideSegment where
* the value_type is equivilent to the common type of
* @begin, @end, and @stride. If there is no common
* type, then a compiler error will be produced.
*/
template <typename BeginT,
typename EndT,
typename StrideT,
typename Common = detail::common_type_t<BeginT, EndT>>
RAJA_HOST_DEVICE TypedRangeStrideSegment<Common> make_range(
BeginT&& begin,
EndT&& end,
StrideT&& stride)
{
static_assert(std::is_signed<StrideT>::value, "make_range : stride must be signed.");
static_assert(std::is_same<make_signed_t<EndT>, StrideT>::value, "make_range : stride and end must be of similar types.");
return {begin, end, stride};
}

/*!
* \brief Function to make a TypedRangeStride Segment for the interval
* [begin, end) with given stride
Expand All @@ -566,8 +603,8 @@ RAJA_HOST_DEVICE TypedRangeStrideSegment<Common> make_strided_range(
EndT&& end,
StrideT&& stride)
{
static_assert(std::is_signed<StrideT>::value, "make_strided_segment : stride must be signed.");
static_assert(std::is_same<make_signed_t<EndT>, StrideT>::value, "make_stride_segment : stride and end must be of similar types.");
static_assert(std::is_signed<StrideT>::value, "make_strided_range : stride must be signed.");
static_assert(std::is_same<make_signed_t<EndT>, StrideT>::value, "make_stride_range : stride and end must be of similar types.");
return {begin, end, stride};
}

Expand Down Expand Up @@ -597,6 +634,62 @@ DefineTypeTraitFromConcept(is_range_stride_constructible,

} // namespace type_traits

// range creation helpers

/*!
* \brief Function to make a TypedRangeSegment for the interval [0, end)
*
* \return a newly constructed TypedRangeSegment where the
* value_type is equivilent to the common type of
* @begin and @end. If there is no common type, then
* a compiler error will be produced.
*/
template <typename EndT>
RAJA_HOST_DEVICE TypedRangeSegment<EndT> range(EndT&& end)
{
return {0, end};
}

/*!
* \brief Function to make a TypedRangeSegment for the interval [begin, end)
*
* \return a newly constructed TypedRangeSegment where the
* value_type is equivilent to the common type of
* @begin and @end. If there is no common type, then
* a compiler error will be produced.
*/
template <typename BeginT,
typename EndT,
typename Common = detail::common_type_t<BeginT, EndT>>
RAJA_HOST_DEVICE TypedRangeSegment<Common> range(BeginT&& begin,
EndT&& end)
{
return {begin, end};
}

/*!
* \brief Function to make a TypedRangeStride Segment for the interval
* [begin, end) with given stride
*
* \return a newly constructed TypedRangeStrideSegment where
* the value_type is equivilent to the common type of
* @begin, @end, and @stride. If there is no common
* type, then a compiler error will be produced.
*/
template <typename BeginT,
typename EndT,
typename StrideT,
typename Common = detail::common_type_t<BeginT, EndT>>
RAJA_HOST_DEVICE TypedRangeStrideSegment<Common> range(
BeginT&& begin,
EndT&& end,
StrideT&& stride)
{
static_assert(std::is_signed<StrideT>::value, "make_range : stride must be signed.");
static_assert(std::is_same<make_signed_t<EndT>, StrideT>::value, "make_range : stride and end must be of similar types.");
return {begin, end, stride};
}

} // namespace RAJA

namespace std
Expand Down