Compartilhar via


negate (STL/CLR)

The template class describes a functor that, when called, returns its argument negated. You use it specify a function object in terms of its argument type.

template<typename Arg>
    ref class negate
    { // wrap operator()
public:
    typedef Arg argument_type;
    typedef bool result_type;
    typedef Microsoft::VisualC::StlClr::UnaryDelegate<
        argument_type, result_type>
        delegate_type;

    negate();
    negate(negate<Arg>% right);

    result_type operator()(argument_type left);
    operator delegate_type^();
    };

Parameters

  • Arg
    The type of the arguments.

Member Functions

Type Definition

Description

argument_type

The type of the functor argument.

delegate_type

The type of the generic delegate.

result_type

The type of the functor result.

Member

Description

negate

Constructs the functor.

Operator

Description

operator()

Computes the desired function.

operator delegate_type^

Casts the functor to a delegate.

Remarks

The template class describes a one-argument functor. It defines the member operator operator() so that, when the object is called as a function, it returns its argument negated.

You can also pass the object as a function argument whose type is delegate_type^ and it will be converted appropriately.

Example

// cliext_negate.cpp 
// compile with: /clr 
#include <cliext/algorithm> 
#include <cliext/functional> 
#include <cliext/vector> 
 
typedef cliext::vector<int> Myvector; 
int main() 
    { 
    Myvector c1; 
    c1.push_back(4); 
    c1.push_back(-3); 
    Myvector c3(2, 0); 
 
// display initial contents " 4 -3" 
    for each (int elem in c1) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
 
// transform and display 
    cliext::transform(c1.begin(), c1.begin() + 2, 
        c3.begin(), cliext::negate<int>()); 
    for each (int elem in c3) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
    return (0); 
    } 
 
 4 -3
 -4 3

Requirements

Header: <cliext/functional>

Namespace: cliext

See Also

Reference

logical_not (STL/CLR)