C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

hide zero size array with Template Meta Programming

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
laurentoget@gmail.com
Guest





PostPosted: Tue Nov 07, 2006 10:10 am    Post subject: hide zero size array with Template Meta Programming Reply with quote



I have a template class which contains a buffer

char buffer[f(T,...)];

whose size is a function of the template parameters. This works very
well until the template is instanciated for a set of parameters for
which f(T,...) is 0. compilers do not like zero size arrays.

I have a feeling there should be a way to use template metaprogramming
so that the buffer is only there when f(T,...) is >0, but do not know
where to start.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
James Kanze
Guest





PostPosted: Wed Nov 08, 2006 10:10 am    Post subject: Re: hide zero size array with Template Meta Programming Reply with quote



Frederick Gotham wrote:
Quote:
laurentoget (AT) gmail (DOT) com:

char buffer[f(T,...)];

Forgive me, but what the hell is that? At first glance, it looks like the
definition of an array whose dimension is determined by a function
declaration which lacks a return type. . .

Presumably, he is using f() in a mathematical sense here, that
the size is a function of the template parameters (and possibly
other things), and he doesn't mean that the f() is a C++
function. Traditionally, T is the name of the first template
type parameter, and you cannot call a C++ with a template type
parameter as an argument.

--
James Kanze (GABI Software) email:james.kanze (AT) gmail (DOT) com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
laurentoget@gmail.com
Guest





PostPosted: Thu Nov 09, 2006 5:05 pm    Post subject: Re: hide zero size array with Template Meta Programming Reply with quote



James Kanze wrote:
Quote:
Frederick Gotham wrote:
laurentoget (AT) gmail (DOT) com:

char buffer[f(T,...)];

Forgive me, but what the hell is that? At first glance, it looks like the
definition of an array whose dimension is determined by a function
declaration which lacks a return type. . .

Presumably, he is using f() in a mathematical sense here, that
the size is a function of the template parameters (and possibly
other things), and he doesn't mean that the f() is a C++
function. Traditionally, T is the name of the first template
type parameter, and you cannot call a C++ with a template type
parameter as an argument.


exactly,

merci, James,

Laurent


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.