• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. Metafunctions/Miscellaneous//identity |10
2
3identity
4========
5
6Synopsis
7--------
8
9.. parsed-literal::
10
11    template<
12          typename X
13        >
14    struct identity
15    {
16        typedef X type;
17    };
18
19
20Description
21-----------
22
23The `identity`__ metafunction. Returns ``X`` unchanged.
24
25__ http://mathworld.wolfram.com/IdentityFunction.html
26
27
28Header
29------
30
31.. parsed-literal::
32
33    #include <boost/mpl/identity.hpp>
34
35
36Model of
37--------
38
39|Metafunction|
40
41
42Parameters
43----------
44
45+---------------+-------------------+-----------------------------------+
46| Parameter     | Requirement       | Description                       |
47+===============+===================+===================================+
48| ``X``         | Any type          | An argument to be returned.       |
49+---------------+-------------------+-----------------------------------+
50
51
52Expression semantics
53--------------------
54
55For an arbitrary type ``x``:
56
57
58.. parsed-literal::
59
60    typedef identity<x>::type r;
61
62:Return type:
63    A type.
64
65:Semantics:
66    Equivalent to
67
68    .. parsed-literal::
69
70        typedef x r;
71
72
73:Postcondition:
74    ``is_same<r,x>::value == true``.
75
76
77
78Example
79-------
80
81.. parsed-literal::
82
83    typedef apply< identity<_1>, char >::type t1;
84    typedef apply< identity<_2>, char,int >::type t2;
85
86    BOOST_MPL_ASSERT(( is_same< t1, char > ));
87    BOOST_MPL_ASSERT(( is_same< t2, int > ));
88
89
90See also
91--------
92
93|Metafunctions|, |Placeholders|, |Trivial Metafunctions|, |always|, |apply|
94
95
96.. copyright:: Copyright �  2001-2009 Aleksey Gurtovoy and David Abrahams
97   Distributed under the Boost Software License, Version 1.0. (See accompanying
98   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
99