as.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 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_AS_HPP
  11. #define BOOST_COMPUTE_FUNCTIONAL_AS_HPP
  12. namespace boost {
  13. namespace compute {
  14. namespace detail {
  15. template<class T, class Arg>
  16. struct invoked_as
  17. {
  18. invoked_as(const Arg &arg)
  19. : m_arg(arg)
  20. {
  21. }
  22. Arg m_arg;
  23. };
  24. } // end detail namespace
  25. /// The \ref as function converts its argument to type \c T (similar to
  26. /// reinterpret_cast<T>).
  27. ///
  28. /// \see \ref convert "convert<T>"
  29. template<class T>
  30. struct as
  31. {
  32. typedef T result_type;
  33. /// \internal_
  34. template<class Arg>
  35. detail::invoked_as<T, Arg> operator()(const Arg &arg) const
  36. {
  37. return detail::invoked_as<T, Arg>(arg);
  38. }
  39. };
  40. } // end compute namespace
  41. } // end boost namespace
  42. #endif // BOOST_COMPUTE_FUNCTIONAL_AS_HPP