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

(Apple) Clang: compiler error workaround. #51

Merged
merged 1 commit into from
Nov 15, 2022
Merged
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
90 changes: 44 additions & 46 deletions include/kwk/utility/container/shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ namespace kwk
template<std::size_t N, auto Desc>
constexpr auto compress(shape<Desc> const& s) noexcept;

//================================================================================================
//! @brief Generates a kwk::shape from a list of sizes
//! @tparam SizeType Integral type used to store sizes. If unspecified, `std::ptrdiff_t` is used.
//! @param ds Variadic pack of sizes
//================================================================================================
template<typename SizeType, int..., concepts::extent<SizeType>... Ds>
constexpr auto of_size(Ds... ds) noexcept
{
return detail::make_extent<kwk::shape,SizeType>(ds...);
}

template<int..., concepts::extent<std::ptrdiff_t>... Ds>
constexpr auto of_size( Ds... ds) noexcept
{
using type_t = typename detail::largest_type<detail::to_int_t<Ds>...>::type;
return of_size<type_t>(ds...);
}

template<int..., kumi::product_type Ds>
constexpr auto of_size( Ds ds) noexcept
{
return kumi::apply([](auto... s) { return of_size(s...); }, ds);
}

template<typename SizeType,int..., kumi::product_type Ds>
constexpr auto of_size( Ds ds) noexcept
{
return kumi::apply([](auto... s) { return of_size<SizeType>(s...); }, ds);
}

//================================================================================================
//! @ingroup containers
//! @brief Fixed order shape with mixed size capability
Expand Down Expand Up @@ -376,9 +406,21 @@ namespace kwk
//! @return An instance of @ref kwk::shape corresponding to the shape of the selected
//! sub-volume
//==============================================================================================
// has to be defined inline due to (Apple) Clang deficiencies
// https://github.com/llvm/llvm-project/issues/58952
// but also after of_size
//==============================================================================================
template<typename... Slicers>
inline constexpr auto operator()(Slicers const&... s) const noexcept
requires( sizeof...(Slicers) <= static_order);
constexpr auto operator()(Slicers const&... s ) const noexcept
requires( sizeof...(Slicers) <= static_order )
{
auto shd = compress<sizeof...(s)>(*this);
auto sliced = kumi::map_index ( [&](auto i, auto m) { return reshape(shd,m,i); }
, kumi::tie(s...)
);

return kumi::apply( [](auto... v) { return of_size(v...); }, sliced );
}

protected:
template<auto S2, typename Comp, typename Check>
Expand Down Expand Up @@ -445,50 +487,6 @@ namespace kwk
static_cast<new_t&>(that) = compress<N>(static_cast<old_t const&>(s));
return that;
}

//================================================================================================
//! @brief Generates a kwk::shape from a list of sizes
//! @tparam SizeType Integral type used to store sizes. If unspecified, `std::ptrdiff_t` is used.
//! @param ds Variadic pack of sizes
//================================================================================================
template<typename SizeType, int..., concepts::extent<SizeType>... Ds>
constexpr auto of_size(Ds... ds) noexcept
{
return detail::make_extent<kwk::shape,SizeType>(ds...);
}

template<int..., concepts::extent<std::ptrdiff_t>... Ds>
constexpr auto of_size( Ds... ds) noexcept
{
using type_t = typename detail::largest_type<detail::to_int_t<Ds>...>::type;
return of_size<type_t>(ds...);
}

template<int..., kumi::product_type Ds>
constexpr auto of_size( Ds ds) noexcept
{
return kumi::apply([](auto... s) { return of_size(s...); }, ds);
}

template<typename SizeType,int..., kumi::product_type Ds>
constexpr auto of_size( Ds ds) noexcept
{
return kumi::apply([](auto... s) { return of_size<SizeType>(s...); }, ds);
}

// Implementation of slicing interface
template<auto Shape>
template<typename... Slicers>
inline constexpr auto shape<Shape>::operator()(Slicers const&... s) const noexcept
requires( sizeof...(Slicers) <= static_order)
{
auto shd = compress<sizeof...(s)>(*this);
auto sliced = kumi::map_index ( [&](auto i, auto m) { return reshape(shd,m,i); }
, kumi::tie(s...)
);

return kumi::apply( [](auto... v) { return of_size(v...); }, sliced );
}
}

// Tuple interface adaptation
Expand Down