binder1st, bind1st


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

Library

Standards<ToolKit>

Declaration


#include <functional>

template< class Operation >
class binder1st : public unary_function
  <
  typename Operation::second_argument_type,
  typename Operation::result_type
  >
  

Adaptor

binder1st< Operation > bind1st( const Operation& op, const T& x );

Interface

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

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

void
main()
  {
  int* p = remove_if
    (
    array,
    array + 3,
    binder1st< less< int > >( less< int >(), 2 )
    );

  for ( int* i = array; i != p; ++i )
    cout << *i << "\n";
  }

2
3
Example <ospace/osstd/examples/bind1st2.cpp>
#include <iostream>
#include <algorithm>
#include <functional>

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

void
main()
  {
  int* p = remove_if( array, array + 3, bind1st( less< int >(), 2 ) );

  for ( int* i = array; i != p; ++i )
    cout << *i << "\n";
  }

2
3

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