File indexing completed on 2025-01-18 09:30:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_TYPES_PAIR_HPP
0012 #define BOOST_COMPUTE_TYPES_PAIR_HPP
0013
0014 #include <string>
0015 #include <utility>
0016
0017 #include <boost/compute/functional/get.hpp>
0018 #include <boost/compute/type_traits/type_definition.hpp>
0019 #include <boost/compute/type_traits/type_name.hpp>
0020 #include <boost/compute/detail/meta_kernel.hpp>
0021
0022 namespace boost {
0023 namespace compute {
0024 namespace detail {
0025
0026
0027 template<class T1, class T2>
0028 inline meta_kernel&
0029 operator<<(meta_kernel &kernel, const std::pair<T1, T2> &x)
0030 {
0031 kernel << "(" << type_name<std::pair<T1, T2> >() << ")"
0032 << "{" << kernel.make_lit(x.first) << ", "
0033 << kernel.make_lit(x.second) << "}";
0034
0035 return kernel;
0036 }
0037
0038
0039 template<class T1, class T2>
0040 struct inject_type_impl<std::pair<T1, T2> >
0041 {
0042 void operator()(meta_kernel &kernel)
0043 {
0044 typedef std::pair<T1, T2> pair_type;
0045
0046 kernel.inject_type<T1>();
0047 kernel.inject_type<T2>();
0048
0049 kernel.add_type_declaration<pair_type>(type_definition<pair_type>());
0050 }
0051 };
0052
0053
0054 template<class T1, class T2>
0055 struct get_result_type<0, std::pair<T1, T2> >
0056 {
0057 typedef T1 type;
0058 };
0059
0060 template<class T1, class T2>
0061 struct get_result_type<1, std::pair<T1, T2> >
0062 {
0063 typedef T2 type;
0064 };
0065
0066
0067 template<size_t N, class Arg, class T1, class T2>
0068 inline meta_kernel& operator<<(meta_kernel &kernel,
0069 const invoked_get<N, Arg, std::pair<T1, T2> > &expr)
0070 {
0071 kernel.inject_type<std::pair<T1, T2> >();
0072
0073 return kernel << expr.m_arg << (N == 0 ? ".first" : ".second");
0074 }
0075
0076 }
0077
0078 namespace detail {
0079
0080
0081 template<class T1, class T2>
0082 struct type_name_trait<std::pair<T1, T2> >
0083 {
0084 static const char* value()
0085 {
0086 static std::string name =
0087 std::string("_pair_") +
0088 type_name<T1>() + "_" + type_name<T2>() +
0089 "_t";
0090
0091 return name.c_str();
0092 }
0093 };
0094
0095
0096 template<class T1, class T2>
0097 struct type_definition_trait<std::pair<T1, T2> >
0098 {
0099 static std::string value()
0100 {
0101 typedef std::pair<T1, T2> pair_type;
0102
0103 std::stringstream declaration;
0104 declaration << "typedef struct {\n"
0105 << " " << type_name<T1>() << " first;\n"
0106 << " " << type_name<T2>() << " second;\n"
0107 << "} " << type_name<pair_type>() << ";\n";
0108
0109 return declaration.str();
0110 }
0111 };
0112
0113 }
0114 }
0115 }
0116
0117 #endif