#ifndef PYTHONIC_INCLUDE_UTILS_NESTED_CONTAINER_HPP #define PYTHONIC_INCLUDE_UTILS_NESTED_CONTAINER_HPP #include #include "pythonic/include/types/traits.hpp" #include "pythonic/include/utils/numpy_traits.hpp" PYTHONIC_NS_BEGIN namespace types { template class sliced_list; template class list; template struct array_base; template struct dynamic_tuple; } namespace utils { /* compute nested container depth && memory size*/ template struct nested_container_depth_helper; template struct nested_container_depth_helper { static const int value = 0; }; template struct nested_container_depth_helper { static const int value = T::value; }; template struct nested_container_depth { static const int value = nested_container_depth_helper::value>::value; }; template struct nested_container_depth> { static const int value = 1 + nested_container_depth::value; }; template struct nested_container_depth> { static const int value = 1 + nested_container_depth::value; }; template struct nested_container_depth> { static const int value = 1 + nested_container_depth::value; }; template struct nested_container_depth> { static const int value = 1 + nested_container_depth::value; }; template struct nested_container_depth> { static const int value = std::tuple_size::value; }; /* Get the size of a container, using recursion on inner container if any * FIXME: should be a constexpr? * FIXME: why a class && ! a function? */ template struct nested_container_size { using Type = typename std::remove_cv::type>::type; static long flat_size(T const &t); }; /* Recursion stops on bool */ template <> struct nested_container_size { template constexpr static long flat_size(F); }; /* Statically define (by recursion) the type of element inside nested * containers */ template struct nested_container_value_type_helper; template struct nested_container_value_type_helper { using type = T; }; template struct nested_container_value_type_helper { using type = typename T::dtype; }; template struct nested_container_value_type { using type = typename nested_container_value_type_helper< T, types::is_array::value>::type; }; template struct nested_container_value_type> { using type = typename nested_container_value_type::type; }; template struct nested_container_value_type> { using type = typename nested_container_value_type::type; }; template struct nested_container_value_type> { using type = typename nested_container_value_type::type; }; template struct nested_container_value_type> { using type = typename nested_container_value_type::type; }; template struct nested_container_value_type> { using type = T; }; } PYTHONIC_NS_END #endif