1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_DETAIL_PRINT_RANGE_HPP
12 #define BOOST_COMPUTE_DETAIL_PRINT_RANGE_HPP
18 #include <boost/compute/algorithm/copy.hpp>
19 #include <boost/compute/container/vector.hpp>
20 #include <boost/compute/detail/is_buffer_iterator.hpp>
21 #include <boost/compute/detail/iterator_range_size.hpp>
27 template<class InputIterator>
28 inline void print_range(InputIterator first,
31 typename boost::enable_if<
32 is_buffer_iterator<InputIterator>
36 std::iterator_traits<InputIterator>::value_type
39 const size_t size = iterator_range_size(first, last);
41 // copy values to temporary vector on the host
42 std::vector<value_type> tmp(size);
43 ::boost::compute::copy(first, last, tmp.begin(), queue);
47 for(size_t i = 0; i < size; i++){
53 std::cout << " ]" << std::endl;
56 template<class InputIterator>
57 inline void print_range(InputIterator first,
60 typename boost::enable_if_c<
61 !is_buffer_iterator<InputIterator>::value
65 std::iterator_traits<InputIterator>::value_type
68 const context &context = queue.get_context();
69 const size_t size = iterator_range_size(first, last);
71 // copy values to temporary vector on the device
72 ::boost::compute::vector<value_type> tmp(size, context);
73 ::boost::compute::copy(first, last, tmp.begin(), queue);
75 print_range(tmp.begin(), tmp.end(), queue);
78 } // end detail namespace
79 } // end compute namespace
80 } // end boost namespace
82 #endif // BOOST_COMPUTE_DETAIL_PRINT_RANGE_HPP