V
Vijai Kalyan
I was decomposing a task into different policies. Essentially, there is
a general option obtained from a server and user options obtained from
configuration variables. The two options are complementary to one
another.
So I proceeded to decompose the tasks that deal with user options into
two functions. Each of the functions do something and towards the end
they do supplementary tasks that depend on the server option.
The whole things fits in a framework which notifies listeners before
and after the main tasks and so the notification scheme for the
listeners are separate policies as well.
The whole thing is combinatorially complex and hence my decision to
split things up using templates as policies. Here is where I run into
my question: It is exemplified by the following simple code:
#include <iostream>
// main task function
template<class FuncPtr>
void Foo(FuncPtr ptr)
{
ptr();
}
// want to pass an instance of this to Foo
template<class X>
void Bar(X x)
{
x();
}
// want to pass pointer to this to Bar
void G()
{
std::wcout << "From G!" << std::endl;
}
int main()
{
Foo(&Bar(&G)); // doesn't work, coz Bar(&G) is a call to
// function Bar with pointer to G and
// inferred template argument
Foo(&Bar<G>); // don't work becuase the compiler could
// not infer the template argument
// type for overloadl function type from
// overloaded function type
Foo< Bar<G> >( &Bar<G> ); // doesn't work I suppose because
// I should pass the template type as
// pointer to Bar<G> but the compiler
// complains as "invalid template
// argument for FuncPtr; type
// expected"
typedef void (*GPtr) ();
typedef void (*BarGPtr)(GPtr) ;
Foo< BarGPtr >( &Bar<G> ); // doesn't work; compiler complains
// that param 1 for Foo cannot be
// converted from type void(T1) to
// BarGPtr. I suppose T1 is a temporary
// type?
return 0;
}
Any ideas on this?
thanks,
-vijai.
a general option obtained from a server and user options obtained from
configuration variables. The two options are complementary to one
another.
So I proceeded to decompose the tasks that deal with user options into
two functions. Each of the functions do something and towards the end
they do supplementary tasks that depend on the server option.
The whole things fits in a framework which notifies listeners before
and after the main tasks and so the notification scheme for the
listeners are separate policies as well.
The whole thing is combinatorially complex and hence my decision to
split things up using templates as policies. Here is where I run into
my question: It is exemplified by the following simple code:
#include <iostream>
// main task function
template<class FuncPtr>
void Foo(FuncPtr ptr)
{
ptr();
}
// want to pass an instance of this to Foo
template<class X>
void Bar(X x)
{
x();
}
// want to pass pointer to this to Bar
void G()
{
std::wcout << "From G!" << std::endl;
}
int main()
{
Foo(&Bar(&G)); // doesn't work, coz Bar(&G) is a call to
// function Bar with pointer to G and
// inferred template argument
Foo(&Bar<G>); // don't work becuase the compiler could
// not infer the template argument
// type for overloadl function type from
// overloaded function type
Foo< Bar<G> >( &Bar<G> ); // doesn't work I suppose because
// I should pass the template type as
// pointer to Bar<G> but the compiler
// complains as "invalid template
// argument for FuncPtr; type
// expected"
typedef void (*GPtr) ();
typedef void (*BarGPtr)(GPtr) ;
Foo< BarGPtr >( &Bar<G> ); // doesn't work; compiler complains
// that param 1 for Foo cannot be
// converted from type void(T1) to
// BarGPtr. I suppose T1 is a temporary
// type?
return 0;
}
Any ideas on this?
thanks,
-vijai.