473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

tr1::bind in a template class

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::operator(),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::operator()? 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)?

Dec 12 '05 #1
2 4592
Gert Van den Eynde wrote:
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::operator(),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::operator()? 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

Dec 12 '05 #2
Gert Van den Eynde wrote:

std::tr1::bind(&TC::operator(),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.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Dec 26 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: BekTek | last post by:
I have class that has member function that take two argument.. I'd like to use the member function to algorithm such as remove_if.. How can I bind that? class Foo{ void f(){ int a = 10;...
10
by: Clay_Culver | last post by:
I have heard that it is possible to use classes + template magic to make standalone functions (or maybe just a functor which acts like a function) which can accept variable length arguments without...
4
by: Hendrik Schober | last post by:
Hi, this is a cut down version of some some template meta stuff that I have: /////////////////////////////////////////////////////// template< typename TL, typename TR > struct Dummy1 {}; ...
4
by: Dan Krantz | last post by:
I have the following template to ensure that a given number (val) falls into a range (between vmin & vmax): template<typename T> T ForceNumericRange( const T& val, const T& vmin, const T& vmax)...
0
by: tonychestnut | last post by:
Hi, I'm trying to write an interesting bit of code that treats a Boost bind expression as a subexpression in a TR1 bind expression. So, I was trying to do so by specializing is_bind_expression....
6
by: Alex Buell | last post by:
I think one of the program snippets in the Boost's Bind library is wrong. I've just been trying to find the error in this program as below, perhaps there's an typo in there somewhere but I can't...
2
by: Emmanuel Deloget | last post by:
Hello, I'm trying to find a (sfinae powered) way to verify if a particular type declares a subtype (either using typedef or by declaring a subclass). To be more concrete, let's say that I'm...
6
by: abir | last post by:
i have a template template<typename Sclass Indexer{}; i want to have a specialization for std::vector both const & non const version. template<typename T,typename Aclass Indexer<std::vector<T,A...
11
by: Juha Nieminen | last post by:
I'm writing an STL-style data container, and this problem is puzzling me. The following code should demonstrate the problem: //---------------------------------------------------------- #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.