identity.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #ifndef BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP
  11. #define BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP
  12. namespace boost {
  13. namespace compute {
  14. namespace detail {
  15. template<class T, class Arg>
  16. struct invoked_identity
  17. {
  18. typedef T result_type;
  19. invoked_identity(const Arg &arg)
  20. : m_arg(arg)
  21. {
  22. }
  23. Arg m_arg;
  24. };
  25. } // end detail namespace
  26. /// Identity function which simply returns its input.
  27. ///
  28. /// For example, to directly copy values using the transform() algorithm:
  29. /// \code
  30. /// transform(input.begin(), input.end(), output.begin(), identity<int>(), queue);
  31. /// \endcode
  32. ///
  33. /// \see \ref as "as<T>", \ref convert "convert<T>"
  34. template<class T>
  35. class identity
  36. {
  37. public:
  38. /// Identity function result type.
  39. typedef T result_type;
  40. /// Creates a new identity function.
  41. identity()
  42. {
  43. }
  44. /// \internal_
  45. template<class Arg>
  46. detail::invoked_identity<T, Arg> operator()(const Arg &arg) const
  47. {
  48. return detail::invoked_identity<T, Arg>(arg);
  49. }
  50. };
  51. } // end compute namespace
  52. } // end boost namespace
  53. #endif // BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP