// // Copyright (c) 2018-2020, Cem Bassoy, cem.bassoy@gmail.com // Copyright (c) 2019-2020, Amit Singh, amitsingh19975@gmail.com // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // The authors gratefully acknowledge the support of // Google and Fraunhofer IOSB, Ettlingen, Germany // #ifndef _BOOST_UBLAS_TEST_TENSOR_UTILITY_ #define _BOOST_UBLAS_TEST_TENSOR_UTILITY_ #include template struct zip_helper; template struct zip_helper, type1> { template struct with { using type = std::tuple...>; }; template using with_t = typename with::type; }; template struct zip_helper, type1, types1...> { template struct with { using next_tuple = std::tuple...>; using type = typename zip_helper::template with::type; }; template using with_t = typename with::type; }; template using zip = zip_helper,types...>; template struct for_each_tuple_impl{ auto operator()(std::tuple& t, CallBack call_back){ call_back(I,std::get(t)); if constexpr(sizeof...(Ts) - 1 > I){ for_each_tuple_impl it; it(t,call_back); } } }; template auto for_each_tuple(std::tuple& t, CallBack call_back){ for_each_tuple_impl<0,CallBack,Ts...> f; f(t,call_back); } template struct list{ static constexpr size_t size = sizeof...(Ts); }; template struct for_each_list_impl{ constexpr decltype(auto) operator()(list l, CallBack call_back){ using new_list = list; using value_type = T; call_back(I,value_type{}); if constexpr(new_list::size != 0){ for_each_list_impl it; it(new_list{},call_back); } } }; template auto for_each_list(list l, CallBack call_back){ for_each_list_impl<0,CallBack,Ts...> f; f(l,call_back); } #include // To counter msvc warninig C4244 template struct inner_type{ using type = T; }; template struct inner_type< std::complex >{ using type = T; }; template using inner_type_t = typename inner_type::type; // creates e.g. // using test_types = zip::with_t; // equals // using test_types = std::tuple< std::pair, std::pair, std::pair, std::pair //>; //static_assert(std::is_same< std::tuple_element_t<0,std::tuple_element_t<0,test_types2>>, float>::value,"should be float "); //static_assert(std::is_same< std::tuple_element_t<1,std::tuple_element_t<0,test_types2>>, boost::numeric::ublas::first_order>::value,"should be boost::numeric::ublas::first_order "); #endif