Adobe Systems Incorporated


Category: functors Component type: type


Identity is a UnaryFunction that represents the identity function: it takes a single argument x, and returns x.


int main()
  int x = 137;
  identity<int> id;
  assert(x == id(x));   


Defined in the standard header functional, and in the nonstandard backward-compatibility header function.h. This class is an SGI extension; it is not part of the C++ standard.

Template parameters

Parameter Description Default
T The function object's argument type, and return type. [1]  

Model of


Type requirements


Public base classes

unary_function<T, T>


Member Where defined Description
argument_type AdaptableUnaryFunction The type of identity's argument: T.
result_type AdaptableUnaryFunction The type of the result: T. [1]
const T& operator()(const T&) const AdaptableUnaryFunction Function call. The return value is simply the argument.

New members

All of identity's members are defined in the AdaptableUnaryFunction requirements. Identity does not introduce any new members.


[1] It is essential that the return type and the argument type are the same: generalizing identity to allow them to differ would not work. The reason is that identity returns a const reference to its argument, rather than a copy of its argument. If identity were allowed to perform a conversion, then this would be a dangling reference.

See also

The functors, select1st, select2nd, project1st, project2nd

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google