Questions tagged [bind2nd]

The deprecated C++ function template std::bind2nd() generates an unary function object from a binary function object by fixing the second parameter.

std::bind2nd is (as part of the standard, INCITS/ISO/IEC 14882-2011) a deprecated function template in the C++ general utilities library (function objects; header <functional>).

It can (but should -in C++11- no longer) be used to perform Partial function application by creating an unary function object from a binary function object by binding the second parameter to a certain value.

In C++11, it's functionality can be shaped with the help of std::bind / instead.

17 questions
16
votes
3 answers

A replacement for std::bind2nd

I have a foo which is a std::vector. It represents the "edge" values for a set of ranges. For example, if foo is {1, 3, 5, 7, 11} then the ranges are 1-3, 3-5, 5-7, 7-11. Significantly for me, this equates to 4 periods. Note that each period…
P45 Imminent
  • 8,319
  • 4
  • 35
  • 78
12
votes
3 answers

Eigen & GCC 5 : class std::binder2nd is deprecated

I just restarted working on a project which has been on hold for a few months. Last time I compiled it it was working just fine, without any error nor warning. Yet when I tried to compile it earlier today I got this warning attention :…
Amxx
  • 3,020
  • 2
  • 24
  • 45
8
votes
2 answers

weird compiler error using bind2nd(): "member function already defined or declared" instead of "reference to reference"

I recently spent quite some time understanding the error message when calling func() in this piece of code: int main() { vector< vector > v; double sum = 0; for_each( v.begin(), v.end(), bind2nd( ptr_fun(func), &sum )…
Grim Fandango
  • 2,296
  • 1
  • 19
  • 27
4
votes
1 answer

Is there a built-in Haskell equivalent for C++'s std::bind2nd?

What I'm missing is the ability to partially apply the second argument of a function rather than the first. This is especially useful when I want to pass the function to something like map, but without having to write a lambda for it each time. I…
Michel
  • 1,456
  • 11
  • 16
3
votes
1 answer

std::bind2nd and std::bind with bidimensional arrays and arrays of structs

I know that C++ have lambdas and std::bind1st, std::bind2nd and std::bind are deprecated. However, start with the foundations of C++, we can understand better new features. So, I start with this very simple code, using an array of ints: First…
user7140484
  • 920
  • 6
  • 14
3
votes
1 answer

VS2012 bind2nd is not a member of std

I had some code already working on vs2008 and I am trying to port it to vs2012. On this source code I am using the function bind2nd specified and using std::bind2nd and everything works perfectly. When I compile the same code with vs2012 I get an…
ruba
  • 120
  • 2
  • 9
1
vote
4 answers

Using an STL algorithm on vector of pointers of an object (C++)

I need to count the number of times an object of an array of pointers has the same name(member variable) as the parameter given to a member function. I have tried different approaches, but none of them worked. My code does not even compile. The…
Goshutu
  • 132
  • 10
1
vote
1 answer

Can I replace boost::bind with bind1st/2nd?

Just for better understanding, can I replace the call to boost::bind in the following example with std::bind1st/2nd? Or is it not possible because of returning a reference? Example(shortened): class Pos { public: bool operator==( const Pos&…
name
  • 11
  • 4
1
vote
3 answers

C++ bind2nd question

This was one of the questions showed up on my Final exam. I can't figure out what I'm supposed to do. I know BindSecArg requires a () operator, but not sure what goes inside. In this question you are required to implement something similar to…
akk kur
  • 361
  • 2
  • 5
  • 14
1
vote
0 answers

error C2039: 'bind2nd': is not a member of 'std'

I am working on converting a VS2008 C++ program to VS2017 and am running into the error: error C2039: 'bind2nd': is not a member of 'std' Did some searching and found one recommendation to make the int a size_t, that had no effect. Any more…
Sam Carleton
  • 1,339
  • 7
  • 23
  • 45
1
vote
3 answers

bind2nd in a for_each loop

There is something I currently cannot wrap my head around. I was expecting an output where each element is incremented by 1. Obviously that is not the case. After looking closer, I think that is because the bind2nd function's return value is…
Ely
  • 10,860
  • 4
  • 43
  • 64
1
vote
2 answers

how to use binder and bind2nd functors?

How to use binder2nd, bind2nd, and bind1st? More specifically when to use them and are they necessary? Also, I'm looking for some examples.
Tom
  • 217
  • 1
  • 5
  • 10
0
votes
4 answers

Calling a member function with one parameter (bound) for each object in a container

I have a using namespace std; typedef vector CoilVec; CoilVec Coils; with Coil being a base class for CilCoil and RectCoil, a cilindrical coil and a rectangular coil, respectively. Now I wish to invoke a member function calcField on each…
Wouter
  • 161
  • 1
  • 6
0
votes
2 answers

const_iterator, find_if and bind2nd: no match for call to error

I try to use find_if to find a key in a map by its value. But I can't compile the code: struct IsCurrency : binary_function, string, bool> { bool isCurrency(const pair&…
Arks
  • 569
  • 5
  • 19
0
votes
1 answer

Directly call the return functor from bind1st and bind2nd

The return values of bind1st and bind2nd are derived from unary_function. By calling them, I think they provide a function object that accepts one argument. But this maybe is wrong. Here is my code. template class fun: public…
richard.g
  • 3,585
  • 4
  • 16
  • 26
1
2