Skip to content

Commit

Permalink
Adding indirection for VS2015
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille committed Jul 16, 2020
1 parent 4e297c5 commit e12149e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
49 changes: 29 additions & 20 deletions include/xtensor/xchunked_array.hpp
Expand Up @@ -10,30 +10,40 @@

namespace xt
{
template <class E, class = void>
struct chunk_helper
namespace detail
{
static const auto& chunk_shape(const xexpression<E>& e)
// Workaround for VS2015
template <class E>
using try_chunk_shape = decltype(std::declval<E>().chunk_shape());

template <class E, template <class> class OP, class = void>
struct chunk_helper_impl
{
return e.derived_cast().shape();
}
using is_chunked = std::false_type;
};
static const auto& chunk_shape(const xexpression<E>& e)
{
return e.derived_cast().shape();
}
using is_chunked = std::false_type;
};

template <class E>
struct chunk_helper<E, void_t<decltype(std::declval<E>().chunk_shape())>>
{
static const auto& chunk_shape(const xexpression<E>& e)
template <class E, template <class> class OP>
struct chunk_helper_impl<E, OP, void_t<OP<E>>>
{
return e.derived_cast().chunk_shape();
}
using is_chunked = std::true_type;
};
static const auto& chunk_shape(const xexpression<E>& e)
{
return e.derived_cast().chunk_shape();
}
using is_chunked = std::true_type;
};

template <class E>
using chunk_helper = chunk_helper_impl<E, try_chunk_shape>;
}

template<class E>
constexpr auto is_chunked(const xexpression<E>& e) -> bool
constexpr bool is_chunked(const xexpression<E>& e)
{
using return_type = typename chunk_helper<E>::is_chunked;
using return_type = typename detail::chunk_helper<E>::is_chunked;
return return_type::value;
}

Expand Down Expand Up @@ -189,9 +199,8 @@ namespace xt
template <class E>
xchunked_array(const xexpression<E>& e)
{
const auto& chunk_shape = chunk_helper<E>::chunk_shape(e);
xchunked_array<chunk_type> arr(e, chunk_shape);
*this = arr;
const auto& chunk_shape = detail::chunk_helper<E>::chunk_shape(e);
*this = xchunked_array<chunk_type>(e, chunk_shape);
}

template <class E>
Expand Down
3 changes: 3 additions & 0 deletions test/test_xchunked_array.cpp
Expand Up @@ -44,6 +44,9 @@ namespace xt

TEST(xchunked_array, assign_expression)
{
#ifdef _MSC_FULL_VER
std::cout << "MSC_FULL_VER = " << _MSC_FULL_VER << std::endl;
#endif
std::vector<size_t> shape1 = {2, 2, 2};
std::vector<size_t> chunk_shape1 = {2, 3, 4};
chunked_array a1(shape1, chunk_shape1);
Expand Down

0 comments on commit e12149e

Please sign in to comment.