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_IS_CONTIGUOUS_ITERATOR_HPP
12 #define BOOST_COMPUTE_DETAIL_IS_CONTIGUOUS_ITERATOR_HPP
17 #include <boost/config.hpp>
18 #include <boost/type_traits.hpp>
19 #include <boost/utility/enable_if.hpp>
26 template<class Iterator, class Enable = void>
27 struct _is_contiguous_iterator : public boost::false_type {};
29 // std::vector<T>::iterator = true
30 template<class Iterator>
31 struct _is_contiguous_iterator<
33 typename boost::enable_if<
34 typename boost::is_same<
36 typename std::vector<typename Iterator::value_type>::iterator
39 > : public boost::true_type {};
41 // std::vector<T>::const_iterator = true
42 template<class Iterator>
43 struct _is_contiguous_iterator<
45 typename boost::enable_if<
46 typename boost::is_same<
48 typename std::vector<typename Iterator::value_type>::const_iterator
51 > : public boost::true_type {};
53 // std::valarray<T>::iterator = true
54 template<class Iterator>
55 struct _is_contiguous_iterator<
57 typename boost::enable_if<
58 typename boost::is_same<
60 typename std::valarray<typename Iterator::value_type>::iterator
63 > : public boost::true_type {};
65 // std::valarray<T>::const_iterator = true
66 template<class Iterator>
67 struct _is_contiguous_iterator<
69 typename boost::enable_if<
70 typename boost::is_same<
72 typename std::valarray<typename Iterator::value_type>::const_iterator
75 > : public boost::true_type {};
78 template<class Iterator>
79 struct _is_contiguous_iterator<
81 typename boost::enable_if<
82 boost::is_pointer<Iterator>
84 > : public boost::true_type {};
86 // the is_contiguous_iterator meta-function returns true if Iterator points
87 // to a range of contiguous values. examples of contiguous iterators are
88 // std::vector<>::iterator and float*. examples of non-contiguous iterators
89 // are std::set<>::iterator and std::insert_iterator<>.
91 // the implementation consists of two phases. the first checks that value_type
92 // for the iterator is not void. this must be done as for many containers void
93 // is not a valid value_type (ex. std::vector<void>::iterator is not valid).
94 // after ensuring a non-void value_type, the _is_contiguous_iterator function
95 // is invoked. it has specializations retuning true for all (known) contiguous
96 // iterators types and a default value of false.
97 template<class Iterator, class Enable = void>
98 struct is_contiguous_iterator :
99 public _is_contiguous_iterator<
100 typename boost::remove_cv<Iterator>::type
103 // value_type of void = false
104 template<class Iterator>
105 struct is_contiguous_iterator<
107 typename boost::enable_if<
108 typename boost::is_void<
109 typename Iterator::value_type
112 > : public boost::false_type {};
114 } // end detail namespace
115 } // end compute namespace
116 } // end boost namespace
118 #endif // BOOST_COMPUTE_DETAIL_IS_CONTIGUOUS_ITERATOR_HPP