• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef BOOST_COMPUTE_FUNCTIONAL_GET_HPP
12 #define BOOST_COMPUTE_FUNCTIONAL_GET_HPP
13 
14 #include <cstddef>
15 
16 #include <boost/compute/types/fundamental.hpp>
17 #include <boost/compute/type_traits/scalar_type.hpp>
18 
19 namespace boost {
20 namespace compute {
21 namespace detail {
22 
23 // meta-function returning the result type for get<N>()
24 template<size_t N, class Arg>
25 struct get_result_type
26 {
27     typedef typename scalar_type<Arg>::type type;
28 };
29 
30 template<size_t N, class Arg, class T>
31 struct invoked_get
32 {
33     typedef typename get_result_type<N, T>::type result_type;
34 
invoked_getboost::compute::detail::invoked_get35     invoked_get(const Arg &arg)
36         : m_arg(arg)
37     {
38     }
39 
40     Arg m_arg;
41 };
42 
43 } // end detail namespace
44 
45 /// Returns the \c N'th element of an aggregate type (e.g. scalarN,
46 /// pair, tuple, etc.).
47 ///
48 /// \see \ref field "field<T>"
49 template<size_t N>
50 struct get
51 {
52     /// \internal_
53     template<class> struct result;
54 
55     /// \internal_
56     template<class F, class Arg>
57     struct result<F(Arg)>
58     {
59         typedef typename detail::get_result_type<N, Arg>::type type;
60     };
61 
62     template<class Arg>
63     detail::invoked_get<
64         N, Arg, typename boost::remove_cv<typename Arg::result_type>::type
operator ()boost::compute::get65     > operator()(const Arg &arg) const
66     {
67         typedef typename boost::remove_cv<typename Arg::result_type>::type T;
68 
69         return detail::invoked_get<N, Arg, T>(arg);
70     }
71 };
72 
73 } // end compute namespace
74 } // end boost namespace
75 
76 #endif // BOOST_COMPUTE_FUNCTIONAL_GET_HPP
77