473,385 Members | 1,606 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,385 software developers and data experts.

How to write a binder3 tempalte function?

This is an exercise on TCPL:
Write a b i n d e r 3 () that binds the second and third arguments of
a threeargument function to produce a unary predicate. Give an example
where b i n d e r 3 () is a useful function.
And i got a solution from << C++ solutions>>:
template<typename FO>
struct binder2_3
{
typedef typename FO::result_type result_type;
typedef typename FO::first_argument first_argument;
binder2_3(const FO& fo,
typename FO::second_argument& a2,
typename FO::third_argument& a3)
:fo_(fo), a2_(a2), a3_(a3){}
result_type operator()(first_argument a1){
return fo_(a1, a2_, a3_);
}
private:
FO fo_;
const typename FO::second_argument a2_;
const typename FO::third_argument a3_;
};
template<typename FO, typename P2, typename P3inline
binder2_3<FObinder3(const FO& fo, const P2& a2, const P3& a3){
return binder2_3<FO>(fo, a2, a3);
}

I can't understand the followingn sentence:
typedef typename FO::result_type result_type;
It require FO has a member named result_type ? This is a too restrict
rule.
Could someone give an explaination?
Thanks
Oct 31 '08 #1
1 1578
On Oct 31, 2:39*am, Hill <zhubi...@gmail.comwrote:
This is an exercise on TCPL:
Write a b i n d e r 3 () that binds the second and third arguments of
a threeargument function to produce a unary predicate. Give an example
where b i n d e r 3 () is a useful function.
And i got a solution from << C++ solutions>>:

template<typename FO>
struct binder2_3
{
* * typedef typename FO::result_type result_type;
* * typedef typename FO::first_argument first_argument;
* * binder2_3(const FO& fo,
* * * * * * * typename FO::second_argument& a2,
* * * * * * * typename FO::third_argument& a3)
* * * * :fo_(fo), a2_(a2), a3_(a3){}
* * result_type operator()(first_argument a1){
* * * * return fo_(a1, a2_, a3_);
* * }
private:
* * FO fo_;
* * const typename FO::second_argument a2_;
* * const typename FO::third_argument a3_;};

template<typename FO, typename P2, typename P3inline
binder2_3<FObinder3(const FO& fo, const P2& a2, const P3& a3){
* * return binder2_3<FO>(fo, a2, a3);

}

I can't understand the followingn sentence:
typedef typename FO::result_type result_type;
It require FO has a member named result_type ?
It requires FO to have a type member named result_type: typedef,
struct, class or union.
This is a too restrict rule.
Could someone give an explaination?
This is because your binder object wraps the call to the underlying
functor. The binder has to return the result of the functor call,
therefore to be able to declare the type of the return value of
binder::operator() it needs to know the type of the return value of
the underlying functor.

--
Max

Oct 31 '08 #2

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

Similar topics

1
by: Bob Murdoch | last post by:
I have a situation where I call a COM object from ASP that is supposed to create a file. On occasion, especially during development, the output of the COM function is an error string rather than...
9
by: James Marshall | last post by:
I'm writing a library where I want to override document.write(), but for all document objects; thus, I want to put it in the prototype. I tried Document.prototype.write= my_doc_write ; but it...
2
by: Geoff Wilkins | last post by:
I am using <SCRIPT src=...> to import a Javascript routine from a remote source. I am then using some of the variables given values in the routine, in my own Javascript.. Unfortunately the...
14
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as...
2
by: Eric Mitchell | last post by:
Hello all, I am using the document.write() method to create new content on the same page, however... I need to create a new button using this method (button in HTML). Complicating the matter...
2
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
18
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only...
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.