binder2nd, bind2nd


A unary function object that applies a binary function to a predefined value and another operand. Use the associated adapter function bind2nd() to conveniently construct a binder2nd object directly from a function and a value. This object is called binder2nd because the operand is used as the 2nd parameter to the binary function. The first parameter is supplied. Use binder1st if you want the operand to be used as the first parameter.

Library

Standards<ToolKit>

Declaration


#include <functional>

template< class Operation >
class binder2nd : public unary_function
  <
  typename Operation::first_argument_type,
  typename Operation::result_type
  >
  

Adaptor

binder2nd< Operation > bind2nd( const Operation& op, const T& x );

Interface

Constructor
binder2nd( const Operation& op , const typename Operation::second_argument_type& value )
Constructs a binder2nd object associated with operation op and value value .
()
typename Operation::result_type operator()( const typename Operation::first_argument_type& x ) const
Returns op ( x , value ) .
Example <ospace/osstd/examples/bind2nd1.cpp>
#include <iostream>
#include <algorithm>
#include <functional>

int array[ 3 ] = { 1, 2, 3 };

void
main()
  {
  replace_if
    (
    array,
    array + 3,
    binder2nd< greater< int > >( greater< int >(), 2 ),
    4
    );
  for ( int i = 0; i < 3; ++i )
    cout << array[ i ] << "\n";
  }

1
2
4
Example <ospace/osstd/examples/bind2nd2.cpp>
#include <iostream>
#include <algorithm>
#include <functional>

int array[ 3 ] = { 1, 2, 3 };

void
main()
  {
  replace_if( array, array + 3, bind2nd( greater< int >(), 2 ), 4 );

  for ( int i = 0; i < 3; ++i )
    cout << array[ i ] << "\n";
  }

1
2
4

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.