C
Chris Stankevitz
Hello,
Please consider the following example. In the last two lines of
"main" I specify the first template argument. In particular, I
specify that the arguments are "const". Is there any way I can get
the compiler to deduce this so that I do not need to specify it?
The compiler appears to have "trouble" only when the arguments are
anonymous.
FYI I am using gcc 4.6.3.
Thank you,
Chris
// ==========
struct TSObject {};
struct TSVisitor
{
template<
class TAMutableOrConstFunctor,
class TAMutableOrConstObject>
void Visit(
TAMutableOrConstFunctor& Functor,
TAMutableOrConstObject& Object)
{
Functor(Object);
}
};
struct TSFunctorMM { void operator()( TSObject& Object)
{} };
struct TSFunctorMC { void operator()( TSObject& Object) const
{} };
struct TSFunctorCM { void operator()(const TSObject& Object)
{} };
struct TSFunctorCC { void operator()(const TSObject& Object) const
{} };
int main()
{
TSObject Object;
TSVisitor Visitor;
TSFunctorMM FunctorMM;
TSFunctorMC FunctorMC;
TSFunctorCM FunctorCM;
TSFunctorCC FunctorCC;
Visitor.Visit(FunctorMM, Object);
Visitor.Visit(FunctorMC, Object);
Visitor.Visit(FunctorCM, Object);
Visitor.Visit(FunctorCC, Object);
Visitor.Visit<const TSFunctorMC>(TSFunctorMC(), Object);
Visitor.Visit<const TSFunctorCC>(TSFunctorCC(), Object);
return 0;
}
Please consider the following example. In the last two lines of
"main" I specify the first template argument. In particular, I
specify that the arguments are "const". Is there any way I can get
the compiler to deduce this so that I do not need to specify it?
The compiler appears to have "trouble" only when the arguments are
anonymous.
FYI I am using gcc 4.6.3.
Thank you,
Chris
// ==========
struct TSObject {};
struct TSVisitor
{
template<
class TAMutableOrConstFunctor,
class TAMutableOrConstObject>
void Visit(
TAMutableOrConstFunctor& Functor,
TAMutableOrConstObject& Object)
{
Functor(Object);
}
};
struct TSFunctorMM { void operator()( TSObject& Object)
{} };
struct TSFunctorMC { void operator()( TSObject& Object) const
{} };
struct TSFunctorCM { void operator()(const TSObject& Object)
{} };
struct TSFunctorCC { void operator()(const TSObject& Object) const
{} };
int main()
{
TSObject Object;
TSVisitor Visitor;
TSFunctorMM FunctorMM;
TSFunctorMC FunctorMC;
TSFunctorCM FunctorCM;
TSFunctorCC FunctorCC;
Visitor.Visit(FunctorMM, Object);
Visitor.Visit(FunctorMC, Object);
Visitor.Visit(FunctorCM, Object);
Visitor.Visit(FunctorCC, Object);
Visitor.Visit<const TSFunctorMC>(TSFunctorMC(), Object);
Visitor.Visit<const TSFunctorCC>(TSFunctorCC(), Object);
return 0;
}