diff --git a/include/xtensor/xadapt.hpp b/include/xtensor/xadapt.hpp
index e32258fa3..05acede95 100644
--- a/include/xtensor/xadapt.hpp
+++ b/include/xtensor/xadapt.hpp
@@ -48,7 +48,7 @@ namespace xt
using default_allocator_for_ptr_t = typename default_allocator_for_ptr
::type;
template
- using not_an_array = xtl::negation>;
+ using has_dynamic_size = xtl::negation>;
template
using not_a_pointer = xtl::negation>;
@@ -71,8 +71,8 @@ namespace xt
* @param l the layout_type of the xarray_adaptor
*/
template >,
- detail::not_a_pointer)>
+ XTL_REQUIRES(detail::has_dynamic_size>,
+ detail::not_a_pointer>)>
inline xarray_adaptor, L, std::decay_t>
adapt(C&& container, const SC& shape, layout_type l = L)
{
@@ -88,7 +88,7 @@ namespace xt
* @param l the layout_type of the xarray_adaptor
*/
template >,
+ XTL_REQUIRES(detail::has_dynamic_size>,
std::is_pointer>)>
inline auto adapt(C&& pointer, const SC& shape, layout_type l = L)
{
@@ -107,7 +107,7 @@ namespace xt
* @param strides the strides of the xarray_adaptor
*/
template >,
+ XTL_REQUIRES(detail::has_dynamic_size>,
detail::not_a_layout>)>
inline xarray_adaptor, layout_type::dynamic, std::decay_t>
adapt(C&& container, SC&& shape, SS&& strides)
@@ -131,7 +131,7 @@ namespace xt
* @param alloc the allocator used for allocating / deallocating the dynamic array
*/
template ,
- XTL_REQUIRES(detail::not_an_array>)>
+ XTL_REQUIRES(detail::has_dynamic_size>)>
inline xarray_adaptor, O, A>, L, SC>
adapt(P&& pointer, typename A::size_type size, O ownership, const SC& shape, layout_type l = L, const A& alloc = A())
{
@@ -155,7 +155,7 @@ namespace xt
* @param alloc the allocator used for allocating / deallocating the dynamic array
*/
template ,
- XTL_REQUIRES(detail::not_an_array>,
+ XTL_REQUIRES(detail::has_dynamic_size>,
detail::not_a_layout>)>
inline xarray_adaptor, O, A>, layout_type::dynamic, std::decay_t>
adapt(P&& pointer, typename A::size_type size, O ownership, SC&& shape, SS&& strides, const A& alloc = A())
@@ -178,7 +178,7 @@ namespace xt
* @param l the layout_type of the xarray_adaptor
*/
template >)>
+ XTL_REQUIRES(detail::has_dynamic_size>)>
inline auto adapt(T (&c_array)[N], const SC& shape, layout_type l = L)
{
return adapt(&c_array[0], N, xt::no_ownership(), shape, l);
@@ -192,7 +192,7 @@ namespace xt
* @param strides the strides of the xarray_adaptor
*/
template >,
+ XTL_REQUIRES(detail::has_dynamic_size>,
detail::not_a_layout>)>
inline auto adapt(T (&c_array)[N], SC&& shape, SS&& strides)
{
@@ -228,13 +228,13 @@ namespace xt
* @param l the layout_type of the xtensor_adaptor
*/
template >,
- detail::not_a_pointer)>
- inline xtensor_adaptor::value, L>
+ XTL_REQUIRES(detail::has_fixed_size>,
+ detail::not_a_pointer>)>
+ inline xtensor_adaptor>::value, L>
adapt(C&& container, const SC& shape, layout_type l = L)
{
static_assert(!xtl::is_integral::value, "shape cannot be a integer");
- constexpr std::size_t N = detail::array_size::value;
+ constexpr std::size_t N = detail::get_fixed_size>::value;
using return_type = xtensor_adaptor, N, L>;
return return_type(std::forward(container), shape, l);
}
@@ -246,13 +246,13 @@ namespace xt
* @param l the layout_type of the xtensor_adaptor
*/
template >,
+ XTL_REQUIRES(detail::has_fixed_size>,
std::is_pointer>)>
inline auto adapt(C&& pointer, const SC& shape, layout_type l = L)
{
static_assert(!xtl::is_integral::value, "shape cannot be a integer");
using buffer_type = xbuffer_adaptor>;
- constexpr std::size_t N = detail::array_size::value;
+ constexpr std::size_t N = detail::get_fixed_size>::value;
using return_type = xtensor_adaptor;
return return_type(buffer_type(pointer, compute_size(shape)), shape, l);
}
@@ -265,13 +265,13 @@ namespace xt
* @param strides the strides of the xtensor_adaptor
*/
template >,
+ XTL_REQUIRES(detail::has_fixed_size>,
detail::not_a_layout>)>
- inline xtensor_adaptor::value, layout_type::dynamic>
+ inline xtensor_adaptor>::value, layout_type::dynamic>
adapt(C&& container, SC&& shape, SS&& strides)
{
static_assert(!xtl::is_integral>::value, "shape cannot be a integer");
- constexpr std::size_t N = detail::array_size::value;
+ constexpr std::size_t N = detail::get_fixed_size>::value;
using return_type = xtensor_adaptor, N, layout_type::dynamic>;
return return_type(std::forward(container),
xtl::forward_sequence(shape),
@@ -312,14 +312,14 @@ namespace xt
* @param alloc the allocator used for allocating / deallocating the dynamic array
*/
template ,
- XTL_REQUIRES(detail::is_array>)>
- inline xtensor_adaptor, O, A>, detail::array_size::value, L>
+ XTL_REQUIRES(detail::has_fixed_size>)>
+ inline xtensor_adaptor, O, A>, detail::get_fixed_size>::value, L>
adapt(P&& pointer, typename A::size_type size, O ownership, const SC& shape, layout_type l = L, const A& alloc = A())
{
static_assert(!xtl::is_integral::value, "shape cannot be a integer");
(void)ownership;
using buffer_type = xbuffer_adaptor, O, A>;
- constexpr std::size_t N = detail::array_size::value;
+ constexpr std::size_t N = detail::get_fixed_size>::value;
using return_type = xtensor_adaptor;
buffer_type buf(std::forward(pointer), size, alloc);
return return_type(std::move(buf), shape, l);
@@ -337,15 +337,15 @@ namespace xt
* @param alloc the allocator used for allocating / deallocating the dynamic array
*/
template ,
- XTL_REQUIRES(detail::is_array>,
+ XTL_REQUIRES(detail::has_fixed_size>,
detail::not_a_layout>)>
- inline xtensor_adaptor, O, A>, detail::array_size::value, layout_type::dynamic>
+ inline xtensor_adaptor, O, A>, detail::get_fixed_size>::value, layout_type::dynamic>
adapt(P&& pointer, typename A::size_type size, O ownership, SC&& shape, SS&& strides, const A& alloc = A())
{
static_assert(!xtl::is_integral>::value, "shape cannot be a integer");
(void)ownership;
using buffer_type = xbuffer_adaptor, O, A>;
- constexpr std::size_t N = detail::array_size::value;
+ constexpr std::size_t N = detail::get_fixed_size>::value;
using return_type = xtensor_adaptor;
buffer_type buf(std::forward(pointer), size, alloc);
return return_type(std::move(buf),
@@ -361,7 +361,7 @@ namespace xt
* @param l the layout_type of the xarray_adaptor
*/
template >)>
+ XTL_REQUIRES(detail::has_fixed_size>)>
inline auto adapt(T (&c_array)[N], const SC& shape, layout_type l = L)
{
return adapt(&c_array[0], N, xt::no_ownership(), shape, l);
@@ -375,7 +375,7 @@ namespace xt
* @param strides the strides of the xarray_adaptor
*/
template >,
+ XTL_REQUIRES(detail::has_fixed_size>,
detail::not_a_layout>)>
inline auto adapt(T (&c_array)[N], SC&& shape, SS&& strides)
{
@@ -557,7 +557,7 @@ namespace xt
* @return xarray_adaptor for memory
*/
template >)>
+ XTL_REQUIRES(detail::has_dynamic_size>)>
auto adapt_smart_ptr(P&& smart_ptr, const SC& shape, layout_type l = L)
{
using buffer_adaptor = xbuffer_adaptor>,
+ XTL_REQUIRES(detail::has_dynamic_size>,
detail::not_a_layout>)>
auto adapt_smart_ptr(P&& data_ptr, const SC& shape, D&& smart_ptr, layout_type l = L)
{
diff --git a/include/xtensor/xeval.hpp b/include/xtensor/xeval.hpp
index 84498c199..9d6143003 100644
--- a/include/xtensor/xeval.hpp
+++ b/include/xtensor/xeval.hpp
@@ -80,7 +80,7 @@ namespace xt
template
constexpr bool has_fixed_dims()
{
- return detail::is_array::shape_type>::value;
+ return detail::has_fixed_size::shape_type>::value;
}
template
@@ -102,7 +102,7 @@ namespace xt
template
using as_xtensor_container_t = xtensor::value_type,
- std::tuple_size::shape_type>::value,
+ detail::get_fixed_size::shape_type>::value,
layout_remove_any(L)>;
}
diff --git a/include/xtensor/xfixed.hpp b/include/xtensor/xfixed.hpp
index 82ffed45b..8acdcd6ce 100644
--- a/include/xtensor/xfixed.hpp
+++ b/include/xtensor/xfixed.hpp
@@ -228,7 +228,7 @@ namespace xt
constexpr T get_backstrides(const S& shape, const T& strides) noexcept
{
return detail::get_backstrides_impl(shape, strides,
- std::make_index_sequence::value>{});
+ std::make_index_sequence::value>{});
}
template
@@ -314,7 +314,7 @@ namespace xt
using temporary_type = typename semantic_base::temporary_type;
using expression_tag = Tag;
- constexpr static std::size_t N = std::tuple_size::value;
+ constexpr static std::size_t N = detail::get_fixed_size::value;
constexpr static std::size_t rank = N;
xfixed_container() = default;
@@ -950,4 +950,29 @@ namespace xt
}
}
+/******************************
+ * std::tuple_size extensions *
+ ******************************/
+
+#if defined(__clang__)
+ # pragma clang diagnostic push
+ # pragma clang diagnostic ignored "-Wmismatched-tags"
+#endif
+
+template
+class std::tuple_size> :
+ public std::integral_constant::value>
+{
+};
+
+template
+class std::tuple_size> :
+ public std::integral_constant::value>
+{
+};
+
+#if defined(__clang__)
+ # pragma clang diagnostic pop
+#endif
+
#endif
diff --git a/include/xtensor/xfunction.hpp b/include/xtensor/xfunction.hpp
index 0b21bf44f..73f1dcb04 100644
--- a/include/xtensor/xfunction.hpp
+++ b/include/xtensor/xfunction.hpp
@@ -22,6 +22,7 @@
#include
#include "xaccessible.hpp"
+#include "xaccumulator.hpp"
#include "xexpression_traits.hpp"
#include "xiterable.hpp"
#include "xlayout.hpp"
@@ -913,7 +914,7 @@ namespace xt
// Optimization: no need to compare each subiterator since they all
// are incremented decremented together.
constexpr std::size_t temp = xtl::mpl::find_if::value;
- constexpr std::size_t index = (temp == std::tuple_size::value) ? 0 : temp;
+ constexpr std::size_t index = (temp == detail::get_fixed_size::value) ? 0 : temp;
return std::get(m_it) == std::get(rhs.m_it);
}
@@ -923,7 +924,7 @@ namespace xt
// Optimization: no need to compare each subiterator since they all
// are incremented decremented together.
constexpr std::size_t temp = xtl::mpl::find_if::value;
- constexpr std::size_t index = (temp == std::tuple_size::value) ? 0 : temp;
+ constexpr std::size_t index = (temp == detail::get_fixed_size::value) ? 0 : temp;
return std::get(m_it) < std::get(rhs.m_it);
}
@@ -1059,6 +1060,21 @@ namespace xt
auto step_leading_lambda = [](auto&& st) { st.step_leading(); };
for_each(step_leading_lambda, m_st);
}
+
+ namespace detail
+ {
+ template
+ struct has_fixed_size, std::enable_if_t::shape_type>::value>>
+ : std::true_type
+ {
+ };
+
+ template
+ struct get_fixed_size, std::enable_if_t>::value>>
+ : std::integral_constant::shape_type>::value>
+ {
+ };
+ }
}
#endif
diff --git a/include/xtensor/xreducer.hpp b/include/xtensor/xreducer.hpp
index ae0b962bc..5f25ab0c2 100644
--- a/include/xtensor/xreducer.hpp
+++ b/include/xtensor/xreducer.hpp
@@ -117,9 +117,9 @@ namespace xt
reducer_options(const T& tpl)
{
- xtl::mpl::static_if::value>([this, &tpl](auto no_compile) {
+ xtl::mpl::static_if::value>([this, &tpl](auto no_compile) {
// use no_compile to prevent compilation if initial_val_idx is out of bounds!
- this->initial_value = no_compile(std::get::value ? initial_val_idx : 0>(tpl)).value();
+ this->initial_value = no_compile(std::get::value ? initial_val_idx : 0>(tpl)).value();
},
[](auto /*np_compile*/){}
);
@@ -133,7 +133,7 @@ namespace xt
std::true_type,
std::false_type>;
- constexpr static bool has_initial_value = initial_val_idx != std::tuple_size::value;
+ constexpr static bool has_initial_value = initial_val_idx != detail::get_fixed_size::value;
R initial_value;
diff --git a/include/xtensor/xshape.hpp b/include/xtensor/xshape.hpp
index e9ee57826..10af12da7 100644
--- a/include/xtensor/xshape.hpp
+++ b/include/xtensor/xshape.hpp
@@ -25,6 +25,12 @@
namespace xt
{
+ namespace detail
+ {
+ template
+ struct get_fixed_size;
+ }
+
template
using dynamic_shape = svector;
@@ -231,9 +237,9 @@ namespace xt
};
template
- struct static_dimension_impl::value)>>
+ struct static_dimension_impl::value)>>
{
- static constexpr std::ptrdiff_t value = static_cast(std::tuple_size::value);
+ static constexpr std::ptrdiff_t value = static_cast(detail::get_fixed_size::value);
};
}
@@ -281,7 +287,7 @@ namespace xt
};
template
- struct max_array_size : std::integral_constant::value, max_array_size::value)>
+ struct max_array_size : std::integral_constant::value, max_array_size::value)>
{
};
@@ -375,8 +381,27 @@ namespace xt
static constexpr bool value = true;
};
+ template
+ struct has_fixed_size : std::false_type
+ {
+ };
+
+ template
+ struct has_fixed_size::value)>>
+ : std::true_type
+ {
+ };
+
+ template
+ struct get_fixed_size;
+
+ template
+ struct get_fixed_size::value)>> : std::integral_constant::value>
+ {
+ };
+
template
- using only_array = xtl::conjunction, is_fixed>...>;
+ using only_array = xtl::conjunction, is_fixed, has_fixed_size>...>;
// test that at least one argument is a fixed shape. If yes, then either argument has to be fixed or scalar
template
diff --git a/include/xtensor/xstorage.hpp b/include/xtensor/xstorage.hpp
index f43e75049..4ff81c157 100644
--- a/include/xtensor/xstorage.hpp
+++ b/include/xtensor/xstorage.hpp
@@ -1909,30 +1909,27 @@ namespace xt
# pragma clang diagnostic ignored "-Wmismatched-tags"
#endif
-namespace std
+template
+class std::tuple_size> :
+ public std::integral_constant
{
- template
- class tuple_size> :
- public integral_constant
- {
- };
+};
- template
- class tuple_size> :
- public integral_constant
- {
- };
+template
+class std::tuple_size> :
+ public std::integral_constant
+{
+};
- template
- class tuple_size> :
- public integral_constant
- {
- };
+template
+class std::tuple_size> :
+ public std::integral_constant
+{
+};
- // Undefine tuple size for not-known sequence view size
- template
- class tuple_size>;
-}
+// Undefine tuple size for not-known sequence view size
+template
+class std::tuple_size>;
#if defined(__clang__)
# pragma clang diagnostic pop