CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
set_union.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_UTILITY_SET_UNION_HPP
2 # define CPPAD_UTILITY_SET_UNION_HPP
3 
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 
15 /*
16 $begin set_union$$
17 $spell
18  set
19  const
20  std
21 $$
22 
23 $section Union of Standard Sets$$
24 
25 $head Syntax$$
26 $icode%result% = set_union(%left%, %right%)%$$
27 
28 $head Purpose$$
29 This is a simplified (and restricted) interface to
30 the $code std::union$$ operation.
31 
32 $head Element$$
33 This is the type of the elements of the sets.
34 
35 $head left$$
36 This argument has prototype
37 $codei%
38  const std::set<%Element%>& %left%
39 %$$
40 
41 $head right$$
42 This argument has prototype
43 $codei%
44  const std::set<%Element%>& %right%
45 %$$
46 
47 $head result$$
48 The return value has prototype
49 $codei%
50  std::set<%Element%>& %result%
51 %$$
52 It contains the union of $icode left$$ and $icode right$$.
53 Note that C++11 detects that the return value is a temporary
54 and uses it for the result instead of making a separate copy.
55 
56 $children%
57  example/utility/set_union.cpp
58 %$$
59 $head Example$$
60 The file $cref set_union.cpp$$ contains an example and test of this
61 operation. It returns true if the test passes and false otherwise.
62 
63 
64 $end
65 */
66 
67 # include <set>
68 # include <algorithm>
69 # include <iterator>
70 
71 namespace CppAD {
72  template <class Element>
73  std::set<Element> set_union(
74  const std::set<Element>& left ,
75  const std::set<Element>& right )
76  { std::set<Element> result;
78  left.begin() ,
79  left.end() ,
80  right.begin() ,
81  right.end() ,
82  std::inserter(result, result.begin())
83  );
84  return result;
85  }
86 }
87 
88 # endif
std::set< Element > set_union(const std::set< Element > &left, const std::set< Element > &right)
Definition: set_union.hpp:73