1414#include  < sstream> 
1515#include  < stdexcept> 
1616#include  < string> 
17+ #include  < iostream> 
1718
1819#include  " xtensor_config.hpp" 
20+ #include  < xtl/xsequence.hpp> 
21+ #include  < xtl/xspan_impl.hpp> 
1922
2023namespace  xt 
2124{
25+     struct  missing_type  {};
26+     namespace  {
27+         missing_type missing;
28+     }
29+ 
30+     namespace  detail 
31+     {
32+         template  <class ... Args>
33+         struct  last_type_is_missing_impl 
34+             : std::is_same<missing_type, xtl::mpl::back_t <xtl::mpl::vector<Args...>>>
35+         {
36+         };
37+ 
38+         template  <>
39+         struct  last_type_is_missing_impl <>
40+             : std::false_type
41+         {
42+         };
43+ 
44+         template  <class ... Args>
45+         constexpr  bool  last_type_is_missing = last_type_is_missing_impl<Args...>::value;
46+     }
2247
2348    /* ******************
2449     * broadcast_error * 
@@ -147,6 +172,11 @@ namespace xt
147172        {
148173        }
149174
175+         template  <class  S , std::size_t  dim>
176+         inline  void  check_index_impl (const  S&, missing_type)
177+         {
178+         }
179+ 
150180        template  <class  S , std::size_t  dim, class  T , class ... Args>
151181        inline  void  check_index_impl (const  S& shape, T arg, Args... args)
152182        {
@@ -165,6 +195,11 @@ namespace xt
165195    {
166196    }
167197
198+     template  <class  S >
199+     inline  void  check_index (const  S&, missing_type)
200+     {
201+     }
202+ 
168203    template  <class  S , class  Arg , class ... Args>
169204    inline  void  check_index (const  S& shape, Arg arg, Args... args)
170205    {
@@ -178,6 +213,11 @@ namespace xt
178213            //  Too many arguments: drop the first
179214            check_index (shape, args...);
180215        }
216+         else  if  (detail::last_type_is_missing<Args...>)
217+         {
218+             //  Too few arguments & last argument xt::missing: postfix index with zeros
219+             detail::check_index_impl<S, 0 >(shape, arg, args...);
220+         }
181221        else 
182222        {
183223            //  Too few arguments: ignore the beginning of the shape
@@ -194,7 +234,7 @@ namespace xt
194234        auto  dst = static_cast <size_type>(last - first);
195235        It efirst = last - static_cast <std::ptrdiff_t >((std::min)(shape.size (), dst));
196236        std::size_t  axis = 0 ;
197-          
237+ 
198238        while  (efirst != last)
199239        {
200240            if  (*efirst >= value_type (shape[axis]) && shape[axis] != 1 )
0 commit comments