Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend blocked_nd_range CTAD with tests and explicit deduction guide #1525

Open
wants to merge 8 commits into
base: rarutyun/blocked_range_nd_class
Choose a base branch
from
33 changes: 33 additions & 0 deletions include/oneapi/tbb/blocked_nd_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,39 @@ class blocked_nd_range : public blocked_nd_range_impl<Value, N> {
using base::base;
};

#if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT
template <typename Value, unsigned int N0,
typename... Values, unsigned int... Ns,
typename = std::enable_if_t<(sizeof...(Values) > 0)>,
typename = std::enable_if_t<(... && std::is_same_v<Value, Values>)>,
typename = std::enable_if_t<(N0 == 2 || N0 == 3) && (... && (Ns == 2 || Ns == 3))>>
blocked_nd_range(const Value (&)[N0], const Values (&... dim)[Ns])
-> blocked_nd_range<Value, 1 + sizeof...(Values)>;

template <typename Value, typename... Values,
typename = std::enable_if_t<(... && std::is_same_v<Value, Values>)>>
blocked_nd_range(blocked_range<Value>, blocked_range<Values>...)
-> blocked_nd_range<Value, 1 + sizeof...(Values)>;

template <typename Value, unsigned int N,
typename = std::enable_if_t<(N != 2 && N != 3)>>
blocked_nd_range(const Value (&)[N])
-> blocked_nd_range<Value, N>;

template <typename Value, unsigned int N>
blocked_nd_range(const Value (&)[N], typename blocked_nd_range<Value, N>::size_type)
-> blocked_nd_range<Value, N>;

template <typename Value, unsigned int N>
blocked_nd_range(blocked_nd_range<Value, N>, oneapi::tbb::split)
-> blocked_nd_range<Value, N>;

template <typename Value, unsigned int N>
blocked_nd_range(blocked_nd_range<Value, N>, oneapi::tbb::proportional_split)
-> blocked_nd_range<Value, N>;

#endif // __TBB_CPP17_DEDUCTION_GUIDES_PRESENT

} // namespace d1
} // namespace detail

Expand Down
68 changes: 68 additions & 0 deletions test/conformance/conformance_blocked_nd_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,71 @@ TEST_CASE("blocked_nd_range proportional splitting") {
utils::check_range_bounds_after_splitting(original.dim(0), first.dim(0), second.dim(0), expected_first_end);
}
}

#if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT
//! Testing blocked_rangeNd deduction guides
//! \brief \ref interface
TEST_CASE("blocked_rangeNd deduction guides") {
using oneapi::tbb::blocked_nd_range;

std::vector<const unsigned long*> v;
using iterator = typename decltype(v)::iterator;

oneapi::tbb::blocked_range<int> dim_range(0, 100);

blocked_nd_range<int, 2> source_range(dim_range, dim_range);

{
blocked_nd_range range(dim_range, dim_range, dim_range);
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 3>>);
}
{
blocked_nd_range range({v.begin(), v.end()}, {v.begin(), v.end()});
static_assert(std::is_same_v<decltype(range), blocked_nd_range<iterator, 2>>);
}
{
blocked_nd_range range({0, 100}, {0, 100, 5}, {0, 100}, {0, 100, 5});
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 4>>);
}
{
blocked_nd_range range({100});
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 1>>);
}
{
blocked_nd_range range({100}, 5);
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 1>>);
}
{
blocked_nd_range range({100, 200}, 5);
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 2>>);
}
{
blocked_nd_range range({100, 200, 300}, 5);
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 3>>);
}
{
blocked_nd_range range({100, 200, 300, 400});
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 4>>);
}
{
blocked_nd_range range({100, 200, 300, 400}, 5);
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 4>>);
}
{
blocked_nd_range range(source_range, oneapi::tbb::split{});
static_assert(std::is_same_v<decltype(range), decltype(source_range)>);
}
{
blocked_nd_range range(source_range, oneapi::tbb::proportional_split{1, 3});
static_assert(std::is_same_v<decltype(range), decltype(source_range)>);
}
{
blocked_nd_range range(source_range);
static_assert(std::is_same_v<decltype(range), decltype(source_range)>);
}
{
blocked_nd_range range(std::move(source_range));
static_assert(std::is_same_v<decltype(range), decltype(source_range)>);
}
}
#endif // __TBB_CPP17_DEDUCTION_GUIDES_PRESENT
Loading