tr1::bind in a template class

G

Gert Van den Eynde

Hi all,

I have a template class

template<typename TC> class A{
public:
...
protected:
TC ObjTC;
}

where my possible TC classes should have a memberfunction double
operator()(double). Somewhere in a memberfunction of A I wish to use
tr1::bind in a call to a memberfunction MF like this

std::tr1::bind(&TC::eek:perator(),ObjTC,_1) which maps to a tr1::function
in the argument list of MF.

but it won't compile: g++ 4.0.2 says that _1 is not defined... Has this
something to do with dependent names in a class? Should I have a
typename somwhere around TC::eek:perator()? Please enlighten me...

thanks,
gert

PS a related question: the possible classes for TC should come from one
hierarchy with an abstract base class. Is there a way to force users of
my code to comply (and not have them using a class that happens to have
a similar interface)?
 
P

peter steiner

Gert said:
Hi all,

I have a template class

template<typename TC> class A{
public:
...
protected:
TC ObjTC;
}

where my possible TC classes should have a memberfunction double
operator()(double). Somewhere in a memberfunction of A I wish to use
tr1::bind in a call to a memberfunction MF like this

std::tr1::bind(&TC::eek:perator(),ObjTC,_1) which maps to a tr1::function
in the argument list of MF.

but it won't compile: g++ 4.0.2 says that _1 is not defined... Has this
something to do with dependent names in a class? Should I have a
typename somwhere around TC::eek:perator()? Please enlighten me...

a typename is evidently only necessary if you refer to a type dependend
onto a templated type. that should not be your problem here as you are
refering to a member function, not a type.

as boost::bind is the reference implementation for tr1::bind and up to
version 1.32 was unable to bind member operators your tr1
implementation may still have that limitation. you could try your code
with the latest boost library.
thanks,
gert

PS a related question: the possible classes for TC should come from one
hierarchy with an abstract base class. Is there a way to force users of
my code to comply (and not have them using a class that happens to have
a similar interface)?

see the tr1 extension header <type_traits> that features a
is_base_of<class Base, class Derived> template class with corresponding
traits to check for inheritance relations.

-- peter
 
P

Pete Becker

Gert said:
std::tr1::bind(&TC::eek:perator(),ObjTC,_1) which maps to a tr1::function
in the argument list of MF.

but it won't compile: g++ 4.0.2 says that _1 is not defined

Implementation error or user error, can't tell. TR1 puts the
placeholders in namespace std::tr1::placeholders.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top