• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10 
11 #ifndef BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP
12 #define BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP
13 
14 namespace boost {
15 namespace compute {
16 namespace detail {
17 
18 template<class T, class Arg>
19 struct invoked_identity
20 {
21     typedef T result_type;
22 
invoked_identityboost::compute::detail::invoked_identity23     invoked_identity(const Arg &arg)
24         : m_arg(arg)
25     {
26     }
27 
28     Arg m_arg;
29 };
30 
31 } // end detail namespace
32 
33 /// Identity function which simply returns its input.
34 ///
35 /// For example, to directly copy values using the transform() algorithm:
36 /// \code
37 /// transform(input.begin(), input.end(), output.begin(), identity<int>(), queue);
38 /// \endcode
39 ///
40 /// \see \ref as "as<T>", \ref convert "convert<T>"
41 template<class T>
42 class identity
43 {
44 public:
45     /// Identity function result type.
46     typedef T result_type;
47 
48     /// Creates a new identity function.
identity()49     identity()
50     {
51     }
52 
53     /// \internal_
54     template<class Arg>
operator ()(const Arg & arg) const55     detail::invoked_identity<T, Arg> operator()(const Arg &arg) const
56     {
57         return detail::invoked_identity<T, Arg>(arg);
58     }
59 };
60 
61 } // end compute namespace
62 } // end boost namespace
63 
64 #endif // BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP
65