[Bug c++/58999] New: sizeof ...(T) is very slow than clang
khurshid.normuradov at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Nov 5 09:07:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58999
Bug ID: 58999
Summary: sizeof ...(T) is very slow than clang
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: khurshid.normuradov at gmail dot com
This code doesn't compiled well on gcc, but compiled well with clang, and very
fast.
template< int ... > struct index_sequence{ using type = index_sequence; };
template< typename T> using invoke = typename T :: type ;
template< typename T, typename U > struct concate;
template< int ...i, int ... j>
struct concate< index_sequence<i...>, index_sequence<j...> >
: index_sequence< i... , (j + sizeof ... (i ) )... > {};
// \ /
// ----------
// I think here is slowly.
template< int n>
struct make_index_sequence_help : concate<
invoke< make_index_sequence_help<n/2>>,
invoke< make_index_sequence_help<n-n/2>>
> {};
template<> struct make_index_sequence_help <0> : index_sequence<>{};
template<> struct make_index_sequence_help <1> : index_sequence<0>{};
template< int n> using make_index_sequence = invoke<
make_index_sequence_help<n> >;
int main()
{
using iseq = make_index_sequence< 1024 > ; // successfull
using jseq = make_index_sequence< 1024 * 16 > ; // a lot of compile time!!!
using kseq = make_index_sequence< 1024 * 64 > ; // can't compile: memory
exhauted!!!
};
When I change sizeof...(i) to concrete number 's' - compiled fastest as
clang.
template< int s, typename T, typename U > struct concate;
template< int s, int ...i, int ...j >
struct concate< s, index_sequence<i...>, index_sequence<j...> >
: index_sequence< i..., ( j + s ) ... > {};
// |_ changed sizeof...(i) to s
// and
template< int n >
struct make_index_sequence_help : concate<
n / 2 ,
invoke< make_index_sequence_help< n / 2 > >,
invoke< make_index_sequence_help< n - n/2 > >
>{};
More information about the Gcc-bugs
mailing list