From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11771 invoked by alias); 28 Jul 2010 17:26:20 -0000 Received: (qmail 11748 invoked by uid 22791); 28 Jul 2010 17:26:18 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from lo.gmane.org (HELO lo.gmane.org) (80.91.229.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Jul 2010 17:26:12 +0000 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OeAOO-000487-Fu for gcc@gcc.gnu.org; Wed, 28 Jul 2010 19:26:08 +0200 Received: from r74-192-0-229.bcstcmta01.clsttx.tl.dh.suddenlink.net ([74.192.0.229]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 28 Jul 2010 19:26:08 +0200 Received: from cppljevans by r74-192-0-229.bcstcmta01.clsttx.tl.dh.suddenlink.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 28 Jul 2010 19:26:08 +0200 To: gcc@gcc.gnu.org From: Larry Evans Subject: Re: optimization question: mpl Date: Wed, 28 Jul 2010 17:26:00 -0000 Message-ID: References: <824586E7387D1443B5DD024DAC75B91C139048@SE000319.ztb.icb.commerzbank.com> <824586E7387D1443B5DD024DAC75B91C139049@SE000319.ztb.icb.commerzbank.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Thunderbird 2.0.0.24 (X11/20100317) In-Reply-To: <824586E7387D1443B5DD024DAC75B91C139049@SE000319.ztb.icb.commerzbank.com> X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2010-07/txt/msg00405.txt.bz2 On 07/28/10 10:53, Hite, Christopher wrote: [snip] > struct DecodeContext; > > struct M1{ > static const int id=1; > static void decode(DecodeContext& ){} > }; > > struct M2{ > static const int id=2; > static void decode(DecodeContext& ){} > }; > > struct M3{ > static const int id=3; > static void decode(DecodeContext& ){} > }; > > > template struct ListMember; > > template <> struct ListMember<1>{ typedef M1 type; }; > template <> struct ListMember<2>{ typedef M2 type; }; > template <> struct ListMember<3>{ typedef M3 type; }; > > template > void foo(int id, DecodeContext& dc) { > typedef typename ListMember::type M; > if(M::id==id) > M::decode(dc); > else > foo(id,dc); > } > > template<> > void foo<0>(int id, DecodeContext& dc) {} > > > > int main(){ > DecodeContext& dc= *(DecodeContext*)0;// junk for now > int id=2; //sometime runtime dependent > foo<3>(id,dc); > return 0; > } > [snip] Wouldn't the following simplification work just as well? template struct ListMember{ static void decode(DecodeContext& ){} }; template void foo(int id, DecodeContext& dc) { if(i=id) ListMember::decode(dc); else foo(id,dc); }