public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jack dot q dot word at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/35722] [C++0x] Variadic templates expansion into non-variadic class template Date: Thu, 13 Aug 2009 05:14:00 -0000 [thread overview] Message-ID: <20090813051419.18987.qmail@sourceware.org> (raw) In-Reply-To: <bug-35722-6353@http.gcc.gnu.org/bugzilla/> ------- Comment #11 from jack dot q dot word at gmail dot com 2009-08-13 05:14 ------- (From update of attachment 18348) template< class cT, class... vT > struct VarTypeNav { typedef cT T; typedef VarTypeNav< vT..., void > Next; struct scT { cT v; }; static const size_t Size = sizeof(scT) + Next::Size; static const size_t Count = 1 + Next::Count; }; template< class... vT > struct VarTypeNav< void, vT... > { typedef void T; typedef void Next; static const size_t Size = 0; static const size_t Count = 0; }; template< const size_t nIndex, class cT, class... vT > struct VarTypeSelect { typedef VarTypeSelect< nIndex-1, vT... >::T T; struct scT { T v; }; static const size_t Offset = sizeof(scT) + VarTypeSelect< nIndex-1, vT... >::Offset; }; template< class cT, class... vT > struct VarTypeSelect< 0, cT, vT... > { typedef cT T; static const size_t Offset = 0; }; template< class cT, class... vT > struct Tuple { char Data[VarTypeNav<cT,vT...>::Size]; template< const size_t index > VarTypeSelect< index, vT... >::T & operator [] ( const size_t index ) { static_assert(!(index > VarTypeNav< vT... >::Count ), "Index out of bounds"); char * pThisChars = (char *) this; return *( (VarTypeSelect< index, vT... >::T *) pThisChars[ VarTypeSelect< index, vT... >::Offset ])); } template< const size_t index > const VarTypeSelect< index, vT... >::T & operator [] ( const size_t index ) const { static_assert(!(index > VarTypeNav< vT... >::Count ), "Index out of bounds"); const char * pThisChars = (const char *) this; return *( (const VarTypeSelect< index, vT... >::T *) pThisChars[ VarTypeSelect< index, vT... >::Offset ])); } }; int main() { Tuple< size_t, char * > x; /* = { 32, new char[32] }; *//* ? */ x[0] = 32; x[1] = new char[32]; x[1][31] = 0; return (int) &x[1][0] != 0; } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35722
next prev parent reply other threads:[~2009-08-13 5:14 UTC|newest] Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-03-27 17:32 [Bug c++/35722] New: " dgregor at gcc dot gnu dot org 2008-03-27 17:32 ` [Bug c++/35722] " dgregor at gcc dot gnu dot org 2008-12-02 17:51 ` jason at gcc dot gnu dot org 2009-01-06 19:47 ` jason at gcc dot gnu dot org 2009-01-07 0:06 ` jason at gcc dot gnu dot org 2009-04-04 23:12 ` sebor at roguewave dot com 2009-04-05 4:20 ` jason at gcc dot gnu dot org 2009-04-05 14:20 ` sebor at roguewave dot com 2009-04-05 17:12 ` sebor at roguewave dot com 2009-04-05 19:34 ` jason at gcc dot gnu dot org 2009-08-13 5:01 ` jack dot q dot word at gmail dot com 2009-08-13 5:05 ` jack dot q dot word at gmail dot com 2009-08-13 5:06 ` jack dot q dot word at gmail dot com 2009-08-13 5:14 ` jack dot q dot word at gmail dot com [this message] 2010-01-22 9:12 ` chris at bubblescope dot net [not found] <bug-35722-4@http.gcc.gnu.org/bugzilla/> 2011-01-04 22:53 ` dodji at gcc dot gnu.org 2011-05-20 17:20 ` 3dw4rd at verizon dot net 2011-05-20 20:05 ` tristan.wibberley at gmail dot com 2011-09-27 15:35 ` dodji at gcc dot gnu.org 2011-10-02 21:46 ` jason at gcc dot gnu.org 2011-10-02 21:53 ` jason at gcc dot gnu.org 2011-10-14 19:17 ` jason at gcc dot gnu.org 2012-04-16 2:12 ` jason at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20090813051419.18987.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).