//---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_FUNCTIONAL_DETAIL_UNPACK_HPP #define BOOST_COMPUTE_FUNCTIONAL_DETAIL_UNPACK_HPP #include #include #include #include #include namespace boost { namespace compute { namespace detail { template struct invoked_unpacked { invoked_unpacked(const Function &f, const Arg &arg) : m_function(f), m_arg(arg) { } Function m_function; Arg m_arg; }; template inline meta_kernel& operator<<(meta_kernel &k, const invoked_unpacked &expr); template inline meta_kernel& operator<<(meta_kernel &k, const invoked_unpacked &expr) { return k << expr.m_function(get<0>()(expr.m_arg)); } template inline meta_kernel& operator<<(meta_kernel &k, const invoked_unpacked &expr) { return k << expr.m_function(get<0>()(expr.m_arg), get<1>()(expr.m_arg)); } template inline meta_kernel& operator<<(meta_kernel &k, const invoked_unpacked &expr) { return k << expr.m_function(get<0>()(expr.m_arg), get<1>()(expr.m_arg), get<2>()(expr.m_arg)); } template struct unpacked { template struct aggregate_length { BOOST_STATIC_CONSTANT(size_t, value = boost::tuples::length::value); }; template struct aggregate_length >::type> { BOOST_STATIC_CONSTANT(size_t, value = vector_size::value); }; template struct result_impl {}; template struct result_impl { typedef typename detail::get_result_type<0, TupleArg>::type T1; typedef typename boost::compute::result_of::type type; }; template struct result_impl { typedef typename detail::get_result_type<0, TupleArg>::type T1; typedef typename detail::get_result_type<1, TupleArg>::type T2; typedef typename boost::compute::result_of::type type; }; template struct result_impl { typedef typename detail::get_result_type<0, TupleArg>::type T1; typedef typename detail::get_result_type<1, TupleArg>::type T2; typedef typename detail::get_result_type<2, TupleArg>::type T3; typedef typename boost::compute::result_of::type type; }; template struct result {}; template struct result { typedef typename result_impl::value>::type type; }; unpacked(const Function &f) : m_function(f) { } template detail::invoked_unpacked< Function, Arg, aggregate_length::value > operator()(const Arg &arg) const { return detail::invoked_unpacked< Function, Arg, aggregate_length::value >(m_function, arg); } Function m_function; }; template inline unpacked unpack(const Function &f) { return unpacked(f); } } // end detail namespace } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_FUNCTIONAL_DETAIL_UNPACK_HPP