Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:44:34

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_DETAIL_IS_CONTIGUOUS_ITERATOR_HPP
0012 #define BOOST_COMPUTE_DETAIL_IS_CONTIGUOUS_ITERATOR_HPP
0013 
0014 #include <vector>
0015 #include <valarray>
0016 
0017 #include <boost/config.hpp>
0018 #include <boost/type_traits.hpp>
0019 #include <boost/utility/enable_if.hpp>
0020 
0021 namespace boost {
0022 namespace compute {
0023 namespace detail {
0024 
0025 // default = false
0026 template<class Iterator, class Enable = void>
0027 struct _is_contiguous_iterator : public boost::false_type {};
0028 
0029 // std::vector<T>::iterator = true
0030 template<class Iterator>
0031 struct _is_contiguous_iterator<
0032     Iterator,
0033     typename boost::enable_if<
0034         typename boost::is_same<
0035             Iterator,
0036             typename std::vector<typename Iterator::value_type>::iterator
0037         >::type
0038     >::type
0039 > : public boost::true_type {};
0040 
0041 // std::vector<T>::const_iterator = true
0042 template<class Iterator>
0043 struct _is_contiguous_iterator<
0044     Iterator,
0045     typename boost::enable_if<
0046         typename boost::is_same<
0047             Iterator,
0048             typename std::vector<typename Iterator::value_type>::const_iterator
0049         >::type
0050     >::type
0051 > : public boost::true_type {};
0052 
0053 // std::valarray<T>::iterator = true
0054 template<class Iterator>
0055 struct _is_contiguous_iterator<
0056     Iterator,
0057     typename boost::enable_if<
0058         typename boost::is_same<
0059             Iterator,
0060             typename std::valarray<typename Iterator::value_type>::iterator
0061         >::type
0062     >::type
0063 > : public boost::true_type {};
0064 
0065 // std::valarray<T>::const_iterator = true
0066 template<class Iterator>
0067 struct _is_contiguous_iterator<
0068     Iterator,
0069     typename boost::enable_if<
0070         typename boost::is_same<
0071             Iterator,
0072             typename std::valarray<typename Iterator::value_type>::const_iterator
0073         >::type
0074     >::type
0075 > : public boost::true_type {};
0076 
0077 // T* = true
0078 template<class Iterator>
0079 struct _is_contiguous_iterator<
0080     Iterator,
0081     typename boost::enable_if<
0082         boost::is_pointer<Iterator>
0083     >::type
0084 > : public boost::true_type {};
0085 
0086 // the is_contiguous_iterator meta-function returns true if Iterator points
0087 // to a range of contiguous values. examples of contiguous iterators are
0088 // std::vector<>::iterator and float*. examples of non-contiguous iterators
0089 // are std::set<>::iterator and std::insert_iterator<>.
0090 //
0091 // the implementation consists of two phases. the first checks that value_type
0092 // for the iterator is not void. this must be done as for many containers void
0093 // is not a valid value_type (ex. std::vector<void>::iterator is not valid).
0094 // after ensuring a non-void value_type, the _is_contiguous_iterator function
0095 // is invoked. it has specializations retuning true for all (known) contiguous
0096 // iterators types and a default value of false.
0097 template<class Iterator, class Enable = void>
0098 struct is_contiguous_iterator :
0099     public _is_contiguous_iterator<
0100         typename boost::remove_cv<Iterator>::type
0101     > {};
0102 
0103 // value_type of void = false
0104 template<class Iterator>
0105 struct is_contiguous_iterator<
0106     Iterator,
0107     typename boost::enable_if<
0108         typename boost::is_void<
0109             typename Iterator::value_type
0110         >::type
0111     >::type
0112 > : public boost::false_type {};
0113 
0114 } // end detail namespace
0115 } // end compute namespace
0116 } // end boost namespace
0117 
0118 #endif // BOOST_COMPUTE_DETAIL_IS_CONTIGUOUS_ITERATOR_HPP