Fix compilation of Boost.Range adaptors on GCC 64-bit

[SVN r60904]
This commit is contained in:
Neil Groves
2010-03-28 19:44:33 +00:00
parent bed353556f
commit 40d20d65ca
3 changed files with 75 additions and 127 deletions

View File

@ -18,38 +18,28 @@
namespace boost namespace boost
{ {
namespace range_detail
{
template< class T >
struct copy_holder
: holder2<std::size_t>
{
copy_holder( std::size_t t, std::size_t u )
: holder2<std::size_t>(t,u)
{ }
};
} // 'range_detail'
namespace adaptors namespace adaptors
{ {
template< class CopyableRandomAccessRng, class Int > struct copied
{
copied(std::size_t t_, std::size_t u_)
: t(t_), u(u_) {}
std::size_t t;
std::size_t u;
};
template< class CopyableRandomAccessRng >
inline CopyableRandomAccessRng inline CopyableRandomAccessRng
operator|( const CopyableRandomAccessRng& r, const range_detail::copy_holder<Int>& f ) operator|( const CopyableRandomAccessRng& r, const copied& f )
{ {
iterator_range< iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<const BOOST_DEDUCED_TYPENAME range_iterator<const
CopyableRandomAccessRng>::type > CopyableRandomAccessRng>::type >
temp( range_detail::sliced_impl( r, f ) ); temp( adaptors::slice( r, f.t, f.u ) );
return CopyableRandomAccessRng( temp.begin(), temp.end() ); return CopyableRandomAccessRng( temp.begin(), temp.end() );
} }
namespace
{
const range_detail::forwarder2<range_detail::copy_holder>
copied = range_detail::forwarder2<range_detail::copy_holder>();
}
template<class CopyableRandomAccessRange> template<class CopyableRandomAccessRange>
inline CopyableRandomAccessRange inline CopyableRandomAccessRange
copy(const CopyableRandomAccessRange& rng, std::size_t t, std::size_t u) copy(const CopyableRandomAccessRange& rng, std::size_t t, std::size_t u)

View File

@ -27,7 +27,15 @@
namespace boost namespace boost
{ {
namespace adaptors
{
struct indexed
{
explicit indexed(std::size_t x) : val(x) {}
std::size_t val;
};
}
namespace range_detail namespace range_detail
{ {
template< class Iter > template< class Iter >
@ -35,16 +43,16 @@ namespace boost
: public boost::iterator_adaptor< indexed_iterator<Iter>, Iter > : public boost::iterator_adaptor< indexed_iterator<Iter>, Iter >
{ {
private: private:
typedef boost::iterator_adaptor< indexed_iterator<Iter>, Iter > typedef boost::iterator_adaptor< indexed_iterator<Iter>, Iter >
base; base;
typedef BOOST_DEDUCED_TYPENAME base::difference_type index_type; typedef BOOST_DEDUCED_TYPENAME base::difference_type index_type;
index_type index_; index_type index_;
public: public:
explicit indexed_iterator( Iter i, index_type index ) explicit indexed_iterator( Iter i, index_type index )
: base(i), index_(index) : base(i), index_(index)
{ {
BOOST_ASSERT( index_ >= 0 && "Indexed Iterator out of bounds" ); BOOST_ASSERT( index_ >= 0 && "Indexed Iterator out of bounds" );
} }
@ -53,12 +61,12 @@ namespace boost
{ {
return index_; return index_;
} }
private: private:
friend class boost::iterator_core_access; friend class boost::iterator_core_access;
void increment() void increment()
{ {
++index_; ++index_;
++(this->base_reference()); ++(this->base_reference());
} }
@ -80,7 +88,7 @@ namespace boost
}; };
template< class Rng > template< class Rng >
struct indexed_range : struct indexed_range :
iterator_range< indexed_iterator<BOOST_DEDUCED_TYPENAME range_iterator<Rng>::type> > iterator_range< indexed_iterator<BOOST_DEDUCED_TYPENAME range_iterator<Rng>::type> >
{ {
private: private:
@ -90,49 +98,11 @@ namespace boost
base; base;
public: public:
template< class Index > template< class Index >
indexed_range( Index i, Rng& r ) indexed_range( Index i, Rng& r )
: base( iter_type(boost::begin(r), i), iter_type(boost::end(r),i) ) : base( iter_type(boost::begin(r), i), iter_type(boost::end(r),i) )
{ } { }
}; };
template< class T >
struct index_holder : holder<T>
{
index_holder( T r ) : holder<T>(r)
{ }
};
struct index_forwarder
{
template< class T >
index_holder<T> operator()( T r ) const
{
return r;
}
index_holder<int> operator()( int r = 0 ) const
{
return r;
}
};
template< class SinglePassRange >
inline indexed_range<SinglePassRange>
operator|( SinglePassRange& r,
const index_holder<typename range_difference<SinglePassRange>::type>& f )
{
return indexed_range<SinglePassRange>( f.val, r );
}
template< class SinglePassRange >
inline indexed_range<const SinglePassRange>
operator|( const SinglePassRange& r,
const index_holder<typename range_difference<SinglePassRange>::type>& f )
{
return indexed_range<const SinglePassRange>( f.val, r );
}
} // 'range_detail' } // 'range_detail'
// Make this available to users of this library. It will sometimes be // Make this available to users of this library. It will sometimes be
@ -141,21 +111,30 @@ namespace boost
using range_detail::indexed_range; using range_detail::indexed_range;
namespace adaptors namespace adaptors
{ {
namespace template< class SinglePassRange >
inline indexed_range<SinglePassRange>
operator|( SinglePassRange& r,
const indexed& f )
{ {
const range_detail::forwarder<range_detail::index_holder> return indexed_range<SinglePassRange>( f.val, r );
indexed =
range_detail::forwarder<range_detail::index_holder>();
} }
template< class SinglePassRange >
inline indexed_range<const SinglePassRange>
operator|( const SinglePassRange& r,
const indexed& f )
{
return indexed_range<const SinglePassRange>( f.val, r );
}
template<class SinglePassRange, class Index> template<class SinglePassRange, class Index>
inline indexed_range<SinglePassRange> inline indexed_range<SinglePassRange>
index(SinglePassRange& rng, Index index) index(SinglePassRange& rng, Index index)
{ {
return indexed_range<SinglePassRange>(index, rng); return indexed_range<SinglePassRange>(index, rng);
} }
template<class SinglePassRange, class Index> template<class SinglePassRange, class Index>
inline indexed_range<const SinglePassRange> inline indexed_range<const SinglePassRange>
index(const SinglePassRange& rng, Index index) index(const SinglePassRange& rng, Index index)
@ -163,7 +142,7 @@ namespace boost
return indexed_range<const SinglePassRange>(index, rng); return indexed_range<const SinglePassRange>(index, rng);
} }
} // 'adaptors' } // 'adaptors'
} }
#ifdef BOOST_MSVC #ifdef BOOST_MSVC

View File

@ -19,17 +19,25 @@ namespace boost
{ {
namespace adaptors namespace adaptors
{ {
struct sliced
{
sliced(std::size_t t_, std::size_t u_)
: t(t_), u(u_) {}
std::size_t t;
std::size_t u;
};
template< class RandomAccessRange > template< class RandomAccessRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type > inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type >
slice( RandomAccessRange& rng, std::size_t t, std::size_t u ) slice( RandomAccessRange& rng, std::size_t t, std::size_t u )
{ {
BOOST_ASSERT( t <= u && "error in slice indices" ); BOOST_ASSERT( t <= u && "error in slice indices" );
BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u && BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
"second slice index out of bounds" ); "second slice index out of bounds" );
return make_iterator_range( rng, t, u - boost::size(rng) ); return boost::make_iterator_range( rng, t, u - boost::size(rng) );
} }
template< class RandomAccessRange > template< class RandomAccessRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type > inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type >
slice( const RandomAccessRange& rng, std::size_t t, std::size_t u ) slice( const RandomAccessRange& rng, std::size_t t, std::size_t u )
@ -37,56 +45,27 @@ namespace boost
BOOST_ASSERT( t <= u && "error in slice indices" ); BOOST_ASSERT( t <= u && "error in slice indices" );
BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u && BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
"second slice index out of bounds" ); "second slice index out of bounds" );
return make_iterator_range( rng, t, u - boost::size(rng) ); return boost::make_iterator_range( rng, t, u - boost::size(rng) );
}
} // 'adaptors'
namespace range_detail
{
template< class T >
struct slice_holder
: holder2<std::size_t>
{
slice_holder( std::size_t t, std::size_t u )
: holder2<std::size_t>(t,u)
{ }
};
template<class R, class H>
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<R>::type >
sliced_impl( R& r, const H& f)
{
return adaptors::slice(r, f.val1, f.val2);
}
template< class RandomAccessRange, class Int >
inline iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type >
operator|( RandomAccessRange& r, const slice_holder<Int>& f )
{
return sliced_impl( r, f );
} }
template< class RandomAccessRange, class Int > template< class RandomAccessRange >
inline iterator_range< inline iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type > BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type >
operator|( const RandomAccessRange& r, const slice_holder<Int>& f ) operator|( RandomAccessRange& r, const sliced& f )
{ {
return sliced_impl( r, f ); return adaptors::slice( r, f.t, f.u );
} }
} // 'range_detail' template< class RandomAccessRange >
inline iterator_range<
namespace adaptors BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type >
{ operator|( const RandomAccessRange& r, const sliced& f )
namespace
{ {
const range_detail::forwarder2<range_detail::slice_holder> return adaptors::slice( r, f.t, f.u );
sliced = range_detail::forwarder2<range_detail::slice_holder>();
} }
}
} // namespace adaptors
} } // namespace boost
#endif #endif