Topic: unknown number of parameteres for templates and generic function objects
Author: "jam" <farid.mehrabi@gmail.com>
Date: Mon, 29 Jan 2007 10:20:41 CST Raw View
On Jan 29, 2:15 am, "Daniel Kr gler" <daniel.krueg...@googlemail.com>
wrote:
> On 28 Jan., 18:29, "jam" <farid.mehr...@gmail.com> wrote:
>
>
>
>
>
> > template <typename t1,typename t2 ,... typelist>
> > //end syntax
> > struct funxn{//a generic function object type
> > t1 operator(register t2 ob,typelist ob_list){
> > //do someting
> > .........
> > go(ob_list);
> > .........
> > return ret;//return a t1
> > };
> > };
>
> > void go(int,double);
>
> > static funxn<char,char,int,double> f_ccid;//instantiate the template
>
> > void mycode(void){
> > char ch=f_ccid('a' ,1 , 1.5);//call the function object
> > };---Too late, this idea has already been invented ;-) and you should
> definitely
> read the "variadic template" proposal, which allows all this. See:
>
> http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2087.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2151.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2152.pdf
>
> Greetings from Bremen,
>
> Daniel Kr gler
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-...@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]- Hide quoted
thx 4 lnks but it is not late.const reference can be considered as a
special case of templates I suggest the following syntax to be added:
template <typename A , typename B>
struct tmplt{
//struct difinitions
};
template <typename ... TList>
void funxn(/*syntax*/ tmplt<TList ,int> x/*end syntax*/){
//funxn body here
};
template <typename ... TList>
struct greedy:
//syntax:
tmplt<double ,TList>
//syntax end
{
//type difinition
};
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "jam" <farid.mehrabi@gmail.com>
Date: Mon, 29 Jan 2007 12:01:10 CST Raw View
On Jan 29, 2:15 am, "Daniel Kr gler" <daniel.krueg...@googlemail.com>
wrote:
> On 28 Jan., 18:29, "jam" <farid.mehr...@gmail.com> wrote:
>
>
>
>
>
> > template <typename t1,typename t2 ,... typelist>
> > //end syntax
> > struct funxn{//a generic function object type
> > t1 operator(register t2 ob,typelist ob_list){
> > //do someting
> > .........
> > go(ob_list);
> > .........
> > return ret;//return a t1
> > };
> > };
>
> > void go(int,double);
>
> > static funxn<char,char,int,double> f_ccid;//instantiate the template
>
> > void mycode(void){
> > char ch=f_ccid('a' ,1 , 1.5);//call the function object
> > };---Too late, this idea has already been invented ;-) and you should
> definitely
> read the "variadic template" proposal, which allows all this. See:
>
> http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2087.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2151.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2152.pdf
>
> Greetings from Bremen,
>
> Daniel Kr gler
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-...@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]- Hide quoted
the first example in http://www.generic-programming.org/%7Edgregor/cpp/
variadic-templates.html was exactly what I was going to discuss in my
further posts BUT when is this going to be part of the standards?
you can fancy const reference as a special case of templated types and
have the following syntax:
template<typename A,typename B>
struct atmplt{
//type definition here
};
template<typename ... Tlist>
//syntax
void funxn(atmplt<Tlist,int> x)
//end syntax
{
//funxn body here
};
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "jam" <farid.mehrabi@gmail.com>
Date: Mon, 29 Jan 2007 12:01:13 CST Raw View
On Jan 29, 2:15 am, "Daniel Kr gler" <daniel.krueg...@googlemail.com>
wrote:
> On 28 Jan., 18:29, "jam" <farid.mehr...@gmail.com> wrote:
>
>
>
>
>
> > template <typename t1,typename t2 ,... typelist>
> > //end syntax
> > struct funxn{//a generic function object type
> > t1 operator(register t2 ob,typelist ob_list){
> > //do someting
> > .........
> > go(ob_list);
> > .........
> > return ret;//return a t1
> > };
> > };
>
> > void go(int,double);
>
> > static funxn<char,char,int,double> f_ccid;//instantiate the template
>
> > void mycode(void){
> > char ch=f_ccid('a' ,1 , 1.5);//call the function object
> > };---Too late, this idea has already been invented ;-) and you should
> definitely
> read the "variadic template" proposal, which allows all this. See:
>
> http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2087.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2151.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2152.pdf
>
> Greetings from Bremen,
>
> Daniel Kr gler
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-...@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]- Hide quoted
thx for lnks but why should I regret that it is late?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "=?iso-8859-1?q?Daniel_Kr=FCgler?=" <daniel.kruegler@googlemail.com>
Date: Mon, 29 Jan 2007 14:53:53 CST Raw View
On 29 Jan., 19:01, "jam" <farid.mehr...@gmail.com> wrote:
> thx for lnks but why should I regret that it is late?
I wanted to say, that you are late with your idea, because
others already have made a rather complete Standard
proposal with just that syntax.
Greetings from Bremen,
Daniel Kr gler
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "jam" <farid.mehrabi@gmail.com>
Date: Sat, 3 Feb 2007 09:42:22 CST Raw View
On Jan 29, 2:15 am, "Daniel Kr gler" <daniel.krueg...@googlemail.com>
wrote:
> On 28 Jan., 18:29, "jam" <farid.mehr...@gmail.com> wrote:
>
>
>
>
>
> > template <typename t1,typename t2 ,... typelist>
> > //end syntax
> > struct funxn{//a generic function object type
> > t1 operator(register t2 ob,typelist ob_list){
> > //do someting
> > .........
> > go(ob_list);
> > .........
> > return ret;//return a t1
> > };
> > };
>
> > void go(int,double);
>
> > static funxn<char,char,int,double> f_ccid;//instantiate the template
>
> > void mycode(void){
> > char ch=f_ccid('a' ,1 , 1.5);//call the function object
> > };---
>
> Too late, this idea has already been invented ;-) and you should
> definitely
> read the "variadic template" proposal, which allows all this. See:
>
> http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2087.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2151.pdfhttp://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2152.pdf
>
> Greetings from Bremen,
>
> Daniel Kr gler
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-...@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]- Hide quoted text -
>
> - Show quoted text -
I have just posted the following to <dgregor@osl.iu.edu>:
Standard C++ behavior implicitly defines the unnamed vaiadic global
function pointer template which can replace the redundant function
paramter pack seen in :
std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdfhttp://www2.open-
std.org/jtc1/sc22/wg21/docs/papers/2006/n2087.pdfhttp://www2.open-
std.org/jtc1/sc22/wg21/docs/papers/2007/n2151.pdfhttp://www2.open-
std.org/jtc1/sc22/wg21/docs/papers/2007/n2152.pdf
considering:
template <typename ty> class A;
I prefer the following syntax :
A<ret_type (*)(args...)>
to the newly suggested syntax :
A<ret_type(args...)>
The aforementioned pdf links state that the packed argument to a
variadic templte should be the last one,but I do not see any reason
for it : In contrast to C style variadic functions in which the number
of parameters is not evaluated at compile time and the none-packed
parameters need to be placed at the top of the stack,for templates the
number of elements is caculated at compile time and such a limitation
seems unnecessary.
I suggest the unpack control operator'{}' to be added to variadic
templates.Consider this:
template<typename...> struct Tuple {};
template<typename T1, typename T2> struct Pair {};
template<typename... Args1>
struct zip {
template<typename... Args2>
struct with {
typedef Tuple<Pair<Args1, Args2>...> type;/*tip sizeof...
(Args1)==sizeof...(Args2)*/
};
};
In this example the number of arguments to 'tuple' is the same as that
of 'with' and that of 'zip' .Now look at this:
template<typename...> struct Tuple {};
template<typename T1, typename T2> struct Pair {};
template<typename... Args1>
struct zip {
template<typename... Args2>
struct with {
typedef Tuple<Pair<{Args1}/*prevent unpacking*/
,Args2>...
{Args1...}/*unpack now*/
>
type;
};
};
Here the number of arguments to 'tuple' is 'sizeof...(Args1)*sizeof...
(Args2)'.
I suggest reverse unpacking to be added to the syntax:
template<typename... TArgs>
void forward__unpack(TArgs... vargs );/*vargs are unpacked in the same
order as declaration of TArgs*/
template<typename... TArgs>
void backward_unpack(/*HERE*/...TArgs vargs );/*vargs are unpacked in
the reverse order of declaration of TArgs*/
class A{};
int main(){
int i=1;A a;
forward__unpack<int,a>(i,a);
backward_unpack<int,a>(a,i);/*HERE*/
return 0;
};
I suggest the code unpacking to be included:
template<typename T>
void go(T t);
template<typename T>
void come(T t);
template<typename... TArgs>
void code_unpack(TArgs... vargs ){
go(vargs)... ;/*run go for every parameter from left to right*/
...come(vargs);/*run come for every parameter from right to left*/
};
It is better to add Pseudo typedef instructions for argument packs:
template<typename... TArgs>
struct variadic{
typedef TArgs... same_Args;
typedef ...TArgs reverse_Args;
};
data storage:
For one reason or another one might need to store and retrieve a
packed parameter to and from memory.I have two suggestions for this:
I-member unpacking:
template<typename... TArgs>
struct variadic{
struct forward__pack{
int i;
TArgs... vargs;
};
struct backward_pack{
int i;
...TArgs vargs;
};
};
II-we must be able to treat every class/struct/union whose data
members are accessible acording to access rules,as a parameter pack:
template<typename... TArgs>
struct cap{
static void go(TArgs... vargs);
};
class A{
int private_i;
double private_d;
public:
void go(A a){
cap<{A}...>::go({a}...)/*new syntax with forward packing:call
cap<int,double>::go(i,d)*/
cap<...{A}>::go(...{a})/*new syntax with backward packing:call
cap<double,int>::go(d,i)*/
};
};
ALbeit it is posible to handle data storage and code unpackig using
recursion techniques but that is a dirty way.It is for the same reason
that the 'sizeof...' operator has been suggested.
Finally a variadic template must be able to have a defualt parametr
pack:
struct A;
template<typename... Targs=A,int> struct variadic1;
template<typename... Targs={A}...> struct variadic2;
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "jam" <farid.mehrabi@gmail.com>
Date: Sat, 3 Feb 2007 12:07:07 CST Raw View
On Jan 29, 9:18 pm, Greg Herlihy <gre...@pacbell.net> wrote:
> On 1/28/07 9:29 AM, in article
> 1169989226.999027.182...@m58g2000cwm.googlegroups.com, "jam"
>
> <farid.mehr...@gmail.com> wrote:
> > I was reading the documentation for STL`s <functional> today.Having
> > C#`s delegates in mind ,a long time has passed since I have reached to
> > the disapointing conclusion that in existing versions of C++ compilers
> > and standards there is no proper way to define a generic type safe
> > template for function objects;We are always bound to know the exact
> > number of arguments for templates because no syntax exists for greedy
> > templates(ie templates with unspecified number of type arguments).I
> > can suggest different syntaxes for such purpose but ellipsis is the
> > simplest:
>
> It is possible to declare a C++ function template that will accept a
> variable number of arguments. Just place the arguments into a
> std::tr1::tuple. The template then uses tuple_size to count the number of
> arguments and tuple_element to access each one.
>
> > //syntax:
> > template <typename t1,typename t2 ,... typelist>
> > //end syntax
> > struct funxn{//a generic function object type
> > t1 operator(register t2 ob,typelist ob_list){
> > //do someting
> > .........
> > go(ob_list);
> > .........
> > return ret;//return a t1
> > };
> > };
>
> #include <tr1/tuple> // or <boost/tuple>
>
> using std::tr1::tuple;
> using std::tr1::tuple_size;
> using std::tr1::tuple_element;
>
> template <class T, int N = tuple_size<T>::value>
> struct funxn
> {
> };
>
> Now decompose the tuple type into individual parameters via partial
> specialization:
>
> template< class T >
> struct funxn< T, 0 >
> {
> typedef void R;
>
> void operator ()( )
> {
> // ...
> }
> };
>
> template< class T >
> struct funxn< T, 1 >
> {
> typedef typename tuple_element<0, T>::type R;
>
> R operator ()( )
> {
> // ...
> }
> };
>
> template< class T >
> struct funxn< T, 2>
> {
> typedef typename tuple_element<0, T>::type R;
> typedef typename tuple_element<0, T>::type P1;
>
> R operator ()( const P1& p1 )
> {
> // ...
> }
> };
>
> > void go(int,double);
>
> > static funxn<char,char,int,double> f_ccid;//instantiate the template
>
> > void mycode(void){
> > char ch=f_ccid('a' ,1 , 1.5);//call the function object
> > };
>
> static funxn< tuple< char, char, int, double> f_ccid;
>
> int main()
> {
>
> char ch = _ccid('a', 1, 1.5);
>
> }
>
> Greg
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-...@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]
Ihave not got that library I guess that 'tuple' is a class relying on
partial specialization or recursive templates and my compiler is a
little bit nasty about both.can you explain current standards about
both techniques plz?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "jam" <farid.mehrabi@gmail.com>
Date: Sun, 4 Feb 2007 00:44:35 CST Raw View
On Jan 29, 9:01 pm, "jam" <farid.mehr...@gmail.com> wrote:
> On Jan 29, 2:15 am, "Daniel Kr gler" <daniel.krueg...@googlemail.com>
> wrote:
>
>
>
> > On 28 Jan., 18:29, "jam" <farid.mehr...@gmail.com> wrote:
>
> > > template <typename t1,typename t2 ,... typelist>
> > > //end syntax
> > > struct funxn{//a generic function object type
> > > t1 operator(register t2 ob,typelist ob_list){
> > > //do someting
> > > .........
> > > go(ob_list);
> > > .........
> > > return ret;//return a t1
> > > };
> > > };
>
> > > void go(int,double);
>
> > > static funxn<char,char,int,double> f_ccid;//instantiate the template
>
> > > void mycode(void){
> > > char ch=f_ccid('a' ,1 , 1.5);//call the function object
> > > };---Too late, this idea has already been invented ;-) and you should
> > definitely
> > read the "variadic template" proposal, which allows all this. See:
>
> >http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdfhtt...
>
> > Greetings from Bremen,
>
> > Daniel Kr gler
>
> > ---
> > [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> > [ your news-reader. If that fails, use mailto:std-...@ncar.ucar.edu ]
> > [ --- Please see the FAQ before posting. --- ]
> > [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]- Hide quoted
>
> thx for lnks but why should I regret that it is late?
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-...@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]- Hide quoted text -
>
> - Show quoted text -
I have just posted the following to <dgregor@osl.iu.edu>:
Standard C++ behavior implicitly defines the unnamed vaiadic global
function pointer template which can replace the redundant function
paramter pack seen in :
std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdfhttp://www2.open-
std.org/jtc1/sc22/wg21/docs/papers/2006/n2087.pdfhttp://www2.open-
std.org/jtc1/sc22/wg21/docs/papers/2007/n2151.pdfhttp://www2.open-
std.org/jtc1/sc22/wg21/docs/papers/2007/n2152.pdf
considering:
template <typename ty> class A;
I prefer the following syntax :
A<ret_type (*)(args...)>
to the newly suggested syntax :
A<ret_type(args...)>
The aforementioned pdf links state that the packed argument to a
variadic templte should be the last one,but I do not see any reason
for it : In contrast to C style variadic functions in which the number
of parameters is not evaluated at compile time and the none-packed
parameters need to be placed at the top of the stack,for templates the
number of elements is caculated at compile time and such a limitation
seems unnecessary.
I suggest the unpack control operator'{}' to be added to variadic
templates.Consider this:
template<typename...> struct Tuple {};
template<typename T1, typename T2> struct Pair {};
template<typename... Args1>
struct zip {
template<typename... Args2>
struct with {
typedef Tuple<Pair<Args1, Args2>...> type;/*tip sizeof...
(Args1)==sizeof...(Args2)*/
};
};
In this example the number of arguments to 'tuple' is the same as that
of 'with' and that of 'zip' .Now look at this:
template<typename...> struct Tuple {};
template<typename T1, typename T2> struct Pair {};
template<typename... Args1>
struct zip {
template<typename... Args2>
struct with {
typedef Tuple<Pair<{Args1}/*prevent unpacking*/
,Args2>...
{Args1...}/*unpack now*/
>
type;
};
};
Here the number of arguments to 'tuple' is 'sizeof...(Args1)*sizeof...
(Args2)'.
I suggest reverse unpacking to be added to the syntax:
template<typename... TArgs>
void forward__unpack(TArgs... vargs );/*vargs are unpacked in the same
order as declaration of TArgs*/
template<typename... TArgs>
void backward_unpack(/*HERE*/...TArgs vargs );/*vargs are unpacked in
the reverse order of declaration of TArgs*/
class A{};
int main(){
int i=1;A a;
forward__unpack<int,a>(i,a);
backward_unpack<int,a>(a,i);/*HERE*/
return 0;
};
I suggest the code unpacking to be included:
template<typename T>
void go(T t);
template<typename T>
void come(T t);
template<typename... TArgs>
void code_unpack(TArgs... vargs ){
go(vargs)... ;/*run go for every parameter from left to right*/
...come(vargs);/*run come for every parameter from right to left*/
};
It is better to add Pseudo typedef instructions for argument packs:
template<typename... TArgs>
struct variadic{
typedef TArgs... same_Args;
typedef ...TArgs reverse_Args;
};
data storage:
For one reason or another one might need to store and retrieve a
packed parameter to and from memory.I have two suggestions for this:
I-member unpacking:
template<typename... TArgs>
struct variadic{
struct forward__pack{
int i;
TArgs... vargs;
};
struct backward_pack{
int i;
...TArgs vargs;
};
};
II-we must be able to treat every class/struct/union whose data
members are accessible acording to access rules,as a parameter pack:
template<typename... TArgs>
struct cap{
static void go(TArgs... vargs);
};
class A{
int private_i;
double private_d;
public:
void go(A a){
cap<{A}...>::go({a}...)/*new syntax with forward packing:call
cap<int,double>::go(i,d)*/
cap<...{A}>::go(...{a})/*new syntax with backward packing:call
cap<double,int>::go(d,i)*/
};
};
ALbeit it is posible to handle data storage and code unpackig using
recursion techniques but that is a dirty way.It is for the same reason
that the 'sizeof...' operator has been suggested.
Finally a variadic template must be able to have a defualt parametr
pack:
struct A;
template<typename... Targs=A,int> struct variadic1;
template<typename... Targs={A}...> struct variadic2;
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "jam" <farid.mehrabi@gmail.com>
Date: Sun, 28 Jan 2007 11:29:24 CST Raw View
I was reading the documentation for STL`s <functional> today.Having
C#`s delegates in mind ,a long time has passed since I have reached to
the disapointing conclusion that in existing versions of C++ compilers
and standards there is no proper way to define a generic type safe
template for function objects;We are always bound to know the exact
number of arguments for templates because no syntax exists for greedy
templates(ie templates with unspecified number of type arguments).I
can suggest different syntaxes for such purpose but ellipsis is the
simplest:
//syntax:
template <typename t1,typename t2 ,... typelist>
//end syntax
struct funxn{//a generic function object type
t1 operator(register t2 ob,typelist ob_list){
//do someting
.........
go(ob_list);
.........
return ret;//return a t1
};
};
void go(int,double);
static funxn<char,char,int,double> f_ccid;//instantiate the template
void mycode(void){
char ch=f_ccid('a' ,1 , 1.5);//call the function object
};
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "=?iso-8859-1?q?Daniel_Kr=FCgler?=" <daniel.kruegler@googlemail.com>
Date: Sun, 28 Jan 2007 17:15:42 CST Raw View
On 28 Jan., 18:29, "jam" <farid.mehr...@gmail.com> wrote:
> template <typename t1,typename t2 ,... typelist>
> //end syntax
> struct funxn{//a generic function object type
> t1 operator(register t2 ob,typelist ob_list){
> //do someting
> .........
> go(ob_list);
> .........
> return ret;//return a t1
> };
> };
>
> void go(int,double);
>
> static funxn<char,char,int,double> f_ccid;//instantiate the template
>
> void mycode(void){
> char ch=f_ccid('a' ,1 , 1.5);//call the function object
> };---
Too late, this idea has already been invented ;-) and you should
definitely
read the "variadic template" proposal, which allows all this. See:
http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdf
http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2087.pdf
http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2151.pdf
http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2152.pdf
Greetings from Bremen,
Daniel Kr gler
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]