Alf P. Steinbach
unread,Mar 30, 2017, 7:40:30 AM3/30/17You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
In C++03 perfect forwarding of a sequence of arguments of arbitrary
types, caused a combinatorial explosion in const versus non-const.
In C++11 and later even just writing a function that /accepts/ arbitrary
argument types, when it's desirable to accept std::initializer_list
literals such as `{1, 2, 3}`, causes a combinatorial explosion in
initializer_list (which must known to the compiler as such) versus others.
E.g. in order to be able to call
multi( {1, 2, 3}, {5, 6, 7} )
with up to 3 arguments, a bunch of silly overloads are apparently needed:
template< class... Collections >
class Multidimensional_view_
{
public:
Multidimensional_view_( Collections const&... )
{}
};
template< class... Collections >
inline $f make_multidimensional_view( ref_<const Collections>... c )
-> Multidimensional_view_< Collections... >
{ return Multidimensional_view_< Collections... >{ c... }; }
template< class... Collections >
inline auto multi( ref_<Collections>... c )
{ return make_multidimensional_view( c... ); }
template< class Value >
// i
inline auto multi(
ref_<const initializer_list<Value>> list
)
{ return make_multidimensional_view( list ); }
template< class Collection, class Value >
// ci
inline auto multi(
ref_<const Collection> c,
ref_<const initializer_list<Value>> list
)
{ return make_multidimensional_view( c, list ); }
template< class Value, class Collection >
// ic
inline auto multi(
ref_<const initializer_list<Value>> list,
ref_<const Collection> c
)
{ return make_multidimensional_view( list, c ); }
template< class Value_1, class Value_2 >
// ii
inline $f multi(
ref_<const initializer_list<Value_1>> list_1,
ref_<const initializer_list<Value_2>> list_2
)
{ return make_multidimensional_view( list_1, list_2 ); }
template< class Collection_1, class Collection_2, class Value >
// cci
inline auto multi(
ref_<const Collection_1> c_1,
ref_<const Collection_2> c_2,
ref_<const initializer_list<Value>> list
)
{ return make_multidimensional_view( c_1, c_2, list ); }
template< class Collection_1, class Value, class Collection_2 >
// cic
inline auto multi(
ref_<const Collection_1> c_1,
ref_<const initializer_list<Value>> list,
ref_<const Collection_2> c_2
)
{ return make_multidimensional_view( c_1, list, c_2 ); }
template< class Collection, class Value_1, class Value_2 >
// cii
inline auto multi(
ref_<const Collection> c,
ref_<const initializer_list<Value_1>> list_1,
ref_<const initializer_list<Value_2>> list_2
)
{ return make_multidimensional_view( c, list_1, list_2 ); }
template< class Value, class Collection_1, class Collection_2 >
// icc
inline auto multi(
ref_<const initializer_list<Value>> list,
ref_<const Collection_1> c_1,
ref_<const Collection_2> c_2
)
{ return make_multidimensional_view( list, c_1, c_2 ); }
template< class Value_1, class Collection, class Value_2 >
// ici
inline auto multi(
ref_<const initializer_list<Value_1>> list_1,
ref_<const Collection> c,
ref_<const initializer_list<Value_2>> list_2
)
{ return make_multidimensional_view( list_1, c, list_2 ); }
template< class Value_1, class Value_2, class Collection >
// iic
inline auto multi(
ref_<const initializer_list<Value_1>> list_1,
ref_<const initializer_list<Value_2>> list_2,
ref_<const Collection> c
)
{ return make_multidimensional_view( list_1, list_2, c ); }
template< class Value_1, class Value_2, class Value_3 >
// iii
inline auto multi(
ref_<const initializer_list<Value_1>> list_1,
ref_<const initializer_list<Value_2>> list_2,
ref_<const initializer_list<Value_3>> list_3
)
{ return make_multidimensional_view( list_1, list_2, list_3 ); }
How can this be avoided?
Cheers!,
- Alf