473,583 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function adapters, currying: how to build a generalized binder?

Hello,

as you know the algorithm std::accumulate in the
version

template<class In, class T, class BinOp>
T accumulate(In first, In last, T init, BinOp op)
{
while(first != last) init = op(init,*first+ +);
return init;
}

(from the header <numeric>) requires a binary function
as third argument.

Well, consider if I have a function object like this

struct some_operation
{
double operator()(doub le x, double y, double z)
{
return sin( pow(x*y,2) * z); // or any operation you like
}
}

I would like to bind, say, the first argument x to
a fixed value, then make a binary function out of my
ternary function some_operation, and provide it to
the algorithm std::accumulate .

Is there any standard way to do such binding?
I know the function adapters std::bind1st and std::bind2nd,
but thay work only for binary functions and yeld unary
functions...
Is there any way to use these two binders to build
more general binders?

Best regards,
Giovanni Gh.
Aug 18 '08 #1
2 1896
On Aug 18, 2:01*pm, Giovanni Gherdovich
<gherdov...@stu dents.math.unif i.itwrote:
[...]
Is there any standard way to do such binding?
Check boost.bind, which will also be in the next standard.
I know the function adapters std::bind1st and std::bind2nd,
but thay work only for binary functions and yeld unary
functions...
Is there any way to use these two binders to build
more general binders?
I do not think so, and anyways, any solution involving the (current)
standard binders will easily drive you insane :)

--
gpd

Aug 18 '08 #2
Hello!

gpd:
Check boost.bind, which will also be in the next standard.
Cool!
boost.bind does _exactly_ what I wish!
http://www.boost.org/doc/libs/1_36_0...bind/bind.html

Dear boost project, from now on you have one more fan :-)

Giovanni Gh.
Aug 18 '08 #3

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

Similar topics

8
2514
by: Rico Huijbers | last post by:
Hello, I'd like to know if it's possible to curry a function in PHP? That is, is there some built-in mechanism for it, or is it possible to create a function that does the currying? I've tried something myself, and come up with the following: ---
9
2751
by: Lenard Lindstrom | last post by:
I was wondering if anyone has suggested having Python determine a method's kind from its first parameter. 'self' is a de facto reserved word; 'cls' is a good indicator of a class method ( __new__ is a special case ). The closest to this I could find was the 2002-12-04 posting 'metaclasses and static methods' by Michele Simionato. The...
8
2789
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def _build_used(): .... y = x + 1 .... return x, y ....
1
1802
by: Victor Ng | last post by:
Is there a way to preserve the argspec of a function after wrapping it in a closure? I'm looking for a general way to say "wrap function F in a closure", such that inspect.getargspec on the closure would return the same (args, varargs, varkw, defaults) tuple ass the enclosed function. The typical code I'm using is something like this: ...
0
380
by: Jay Allard | last post by:
Hello I posted this in the vb.net group on the 2/25/2004, but didn't get any response. Here's attempt 2. Does anyone know of a more appropriate place to post this? One new piece of information: It fails on any method that it happens to hit first. I juggled the methods a bit, and it just doesn't matter. As soon as the XslTransform hits an...
8
3398
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; remove_if(list.begin(), list.end(), HERE);
11
4715
by: Marco Loskamp | last post by:
Dear list, I'm trying to dynamically generate functions; it seems that what I really want is beyond C itself, but I'd like to be confirmed here. In the minimal example below, I'd like to create content to put at the address pointed to by f. In particular, I'd like to avoid/replace the memcpy line. Possible application (inspired by Paul...
14
2464
by: Protoman | last post by:
How would you write a function returning a function pointer and why would you need to do this? Is it: int(*)(int&) fn(int& arg); Thanks!!!
6
2255
by: Dasn | last post by:
Hi, there. 'lines' is a large list of strings each of which is seperated by '\t' I wanna split each string into a list. For speed, using map() instead of 'for' loop. 'map(str.split, lines)' works fine , but... when I was trying: I got "TypeError: 'list' object is not callable".
0
7896
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8184
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6581
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5701
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5375
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3820
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1434
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.