Skip to Main Content United States    
PRODUCTS SUPPORT SOLUTIONS SERVICES
COMPAQ SOFTWARE
cxxlstd$help.HLP

Operators

Standard C++ Library Copyright 1996, Rogue Wave Software, Inc.

NAME

operator!=, operator>, operator<=, operator>= - Operators for the C++ Standard C++ Library

SYNOPSIS

#include <utility>

namespace rel_ops {

template <class T> bool operator!= (const T&, const T&);

template <class T> bool operator> (const T&, const T&);

template <class T> bool operator<= (const T&, const T&);

template <class T> bool operator>= (const T&, const T&); }

DESCRIPTION

To avoid redundant definitions of operator!= out of operator== and of operators >, <=, and >= out of operator<, the library provides these definitions:

operator!= returns !(x==y), operator> returns y<x, operator<= returns !(y<x), and operator>= returns !(x<y).

To avoid clashes with other global operators these definitions are contained in the namespace rel_ops. To use them either scope explicitly or provide a using declaration (e.g. using_namespace_rel_ops).

STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee


pair

Standard C++ Library Copyright 1996, Rogue Wave Software, Inc.

NAME

pair - A template for heterogeneous pairs of values.

SYNOPSIS

#include <utility>

template <class T1, class T2> struct pair ;

DESCRIPTION

The pair class provides a template for encapsulating pairs of values that may be of different types.

INTERFACE

template <class T1, class T2> struct pair { T1 first; T2 second; pair(); pair (const T1&, const T2&); ~pair(); };

template <class T1, class T2> bool operator== (const pair<T1, T2>&, const pair T1, T2>&);

template <class T1, class T2> bool operator!= (const pair<T1, T2>&, const pair T1, T2>&);

template <class T1, class T2> bool operator< (const pair<T1, T2>&, const pair T1, T2>&);

template <class T1, class T2> bool operator> (const pair<T1, T2>&, const pair T1, T2>&);

template <class T1, class T2> bool operator<= (const pair<T1, T2>&, const pair T1, T2>&);

template <class T1, class T2> bool operator>= (const pair<T1, T2>&, const pair T1, T2>&);

template <class T1, class T2> pair<T1,T2> make_pair (const T1&, const T2&);

CONSTRUCTORS AND DESTRUCTORS

pair (); Default constructor. Initializes first and second using their default constructors.

pair (const T1& x, const T2& y); The constructor creates a pair of types T1 and T2, making the necessary conversions in x and y.

~pair (); Destructor.

NON-MEMBER OPERATORS

template <class T1, class T2> bool operator== (const pair<T1, T2>& x, const pair T1, T2>& y); Returns true if (x.first == y.first && x.second == y.second) is true. Otherwise it returns false.

template <class T1, class T2> bool operator!= (const pair<T1, T2>& x, const pair T1, T2>& y); Returns !(x==y).

template <class T1, class T2> bool operator< (const pair<T1, T2>& x, const pair T1, T2>& y); Returns true if (x.first < y.first || (!(y.first < x.first) && x.second < y.second)) is true. Otherwise it returns false.

template <class T1, class T2> bool operator> (const pair<T1, T2>& x, const pair T1, T2>& y); Returns y < x.

template <class T1, class T2> bool operator<= (const pair<T1, T2>& x, const pair T1, T2>& y); Returns !(y < x).

template <class T1, class T2> bool operator>= (const pair<T1, T2>& x, const pair T1, T2>& y); Returns !(x < y).

NON-MEMBER FUNCTIONS

template <class T1, class T2> pair<T1,T2> make_pair(x,y); make_pair(x,y) creates a pair by deducing and returning the types of x and y.

STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee


pointer_to_binary_function

Standard C++ Library

NAME

pointer_to_binary_function - A function object which adapts a pointer to a binary function to work where a binary_function is called for.

SYNOPSIS

#include <functional>

template <class Arg1, class Arg2, class Result> class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> ;

DESCRIPTION

The pointer_to_binary_function class encapsulates a pointer to a two- argument function. The class provides an operator() so that the resulting object serves as a binary function object for that function.

The ptr_fun function is overloaded to create instances of a pointer_to_binary_function when provided with the appropriate pointer to a function.

INTERFACE

template <class Arg1, class Arg2, class Result>

class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> { public: typedef typename binary_function<Arg1, Arg2, Result>::second_argument_type second_argument_type; typedef typename binary_function<Arg1, Arg2, Result>::first_argument_type first_argument_type; typedef typename binary_function<Arg1, Arg2, Result>::result_type result_type; explicit pointer_to_binary_function (Result (*f)(Arg1, Arg2)); Result operator() (const Arg1&, const Arg2&) const; };

template<class Arg1, class Arg2, class Result> pointer_to_binary_function<Arg1, Arg2, Result> ptr_fun (Result (*x)(Arg1, Arg2));

SEE ALSO

binary_function, function_objects, pointer_to_unary_function, ptr_fun

STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee


pointer_to_unary_function

Standard C++ Library Copyright 1996, Rogue Wave Software, Inc.

NAME

pointer_to_unary_function - A function object class that adapts a pointer to a function to work where a unary_function is called for.

SYNOPSIS

#include <functional>

template <class Arg, class Result> class pointer_to_unary_function : public unary_function<Arg, Result>;

DESCRIPTION

The pointer_to_unary_function class encapsulates a pointer to a single-argument function. The class provides an operator() so that the resulting object serves as a function object for that function.

The ptr_fun function is overloaded to create instances of pointer_to_unary_function when provided with the appropriate pointer to a function.

INTERFACE

template <class Arg, class Result> class pointer_to_unary_function : public unary_function<Arg, Result> {

public: typedef typename unary_function<Arg,Result>::argument_type argument_type; typedef typename unary_function<Arg,Result>::result_type result_type; explicit pointer_to_unary_function (Result (*f)(Arg)); Result operator() (const Arg&) const; };

template<class Arg, class Result> pointer_to_unary_function<Arg, Result> ptr_fun (Result (*f)(Arg));

SEE ALSO

function_objects, pointer_to_binary_function, ptr_fun, unary_function

STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee


ptr_fun

Standard C++ Library Copyright 1996, Rogue Wave Software, Inc.

NAME

ptr_fun - A function that is overloaded to adapt a pointer to a function to work where a function is called for.

SYNOPSIS

#include <functional>

template<class Arg, class Result> pointer_to_unary_function<Arg, Result> ptr_fun (Result (*f)(Arg));

template<class Arg1, class Arg2, class Result> pointer_to_binary_function<Arg1, Arg2, Result> ptr_fun (Result (*x)(Arg1, Arg2));

DESCRIPTION

The pointer_to_unary_function and pointer_to_binary_function classes encapsulate pointers to functions and provide an operator() so that the resulting object serves as a function object for the function.

The ptr_fun function is overloaded to create instances of pointer_to_unary_function or pointer_to_binary_function when provided with the appropriate pointer to a function.

EXAMPLE

// // pnt2fnct.cpp // #include <functional> #include <deque> #include <vector> #include <algorithm> #include <iostream.h>

//Create a function int factorial(int x) { int result = 1; for(int i = 2; i <= x; i++) result *= i; return result; }

int main() { //Initialize a deque with an array of ints int init[7] = {1,2,3,4,5,6,7}; deque<int> d(init, init+7);

//Create an empty vector to store the factorials vector<int> v((size_t)7);

//Transform the numbers in the deque to their factorials and //store in the vector transform(d.begin(), d.end(), v.begin(), ptr_fun(factorial));

//Print the results cout << "The following numbers: " << endl << " "; copy(d.begin(),d.end(),ostream_iterator<int,char>(cout," "));

cout << endl << endl; cout << "Have the factorials: " << endl << " "; copy(v.begin(),v.end(),ostream_iterator<int,char>(cout," "));

return 0; }

Output : The following numbers: 1 2 3 4 5 6 7 Have the factorials: 1 2 6 24 120 720 5040

WARNING

If your compiler does not support default template parameters, you need to always supply the Allocator template argument. For instance, you will need to write :

vector<int, allocator<int> >

instead of :

vector<int>

SEE ALSO

function_objects, pointer_to_binary_function, pointer_to_unary_function

STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee

Buy Online or Call 1.800.888.0220      privacy statement and legal notices 
STORES CONTACT US SEARCH PRODUCTS SOLUTIONS OPTIONS DEVELOPERS