Improve vacpp support.
[boost.git] / boost / libs / mpl / doc / src / refmanual / unique.rst
blob80bc5513adc462b684dc4452e758bce6f9eaa6f3
1 .. Algorithms/Transformation Algorithms//unique |80
3 unique
4 ======
6 Synopsis
7 --------
9 .. parsed-literal::
10     
11     template<
12           typename Seq
13         , typename Pred
14         , typename In = |unspecified|
15         >
16     struct unique
17     {
18         typedef |unspecified| type;
19     };
22 Description
23 -----------
25 Returns a sequence of the initial elements of every subrange of the
26 original sequence ``Seq`` whose elements are all the same. 
28 |transformation algorithm disclaimer|
30 Header
31 ------
33 .. parsed-literal::
34     
35     #include <boost/mpl/unique.hpp>
38 Model of
39 --------
41 |Reversible Algorithm|
44 Parameters
45 ----------
47 +---------------+-----------------------------------+-------------------------------+
48 | Parameter     | Requirement                       | Description                   |
49 +===============+===================================+===============================+
50 | ``Sequence``  | |Forward Sequence|                | An original sequence.         |
51 +---------------+-----------------------------------+-------------------------------+
52 | ``Pred``      | Binary |Lambda Expression|        | An equivalence relation.      |
53 +---------------+-----------------------------------+-------------------------------+
54 | ``In``        | |Inserter|                        | An inserter.                  |
55 +---------------+-----------------------------------+-------------------------------+
58 Expression semantics
59 --------------------
61 |Semantics disclaimer...| |Reversible Algorithm|.
63 For any |Forward Sequence| ``s``, a binary |Lambda Expression| ``pred``, 
64 and an |Inserter| ``in``:
67 .. parsed-literal::
69     typedef unique<s,pred,in>::type r; 
71 :Return type:
72     A type.
74 :Semantics:
75     If ``size<s>::value <= 1``, then equivalent to
77     .. parsed-literal::
78     
79         typedef copy<s,in>::type r;
80     
81     otherwise equivalent to
83     .. parsed-literal::
85         typedef lambda<pred>::type p;
86         typedef lambda<in::operation>::type in_op;
87         typedef apply_wrap\ ``2``\<
88               in_op
89             , in::state
90             , front<types>::type 
91             >::type in_state;
93         typedef fold<
94               s
95             , pair< in_state, front<s>::type >
96             , eval_if< 
97                   apply_wrap\ ``2``\<p, second<_1>, _2>
98                 , identity< first<_1> >
99                 , apply_wrap\ ``2``\<in_op, first<_1>, _2>
100                 >
101             >::type::first r;
104 Complexity
105 ----------
107 Linear. Performs exactly ``size<s>::value - 1`` applications of ``pred``, and at 
108 most ``size<s>::value`` insertions.
111 Example
112 -------
114 .. parsed-literal::
115     
116     typedef vector<int,float,float,char,int,int,int,double> types;
117     typedef vector<int,float,char,int,double> expected;
118     typedef unique< types, is_same<_1,_2> >::type result;
119     
120     BOOST_MPL_ASSERT(( equal< result,expected > ));
123 See also
124 --------
126 |Transformation Algorithms|, |Reversible Algorithm|, |reverse_unique|, |remove|, |copy_if|, |replace_if|