negate


A unary function object that returns the negation of its operand.

Library

Standards<ToolKit>

Declaration


#include <functional>

template< class T >
struct negate : unary_function< T, T >

Interface

()
T operator()( const T& x ) const
Returns - x .
Example <ospace/osstd/examples/negate.cpp>
#include <iostream>
#include <algorithm>
#include <functional>

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

void
main()
  {
  int output[ 3 ];

  transform( input, input + 3, output, negate< int >() );

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

-1
-2
-3

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