Files
boost_range/include/boost/range/begin.hpp

144 lines
3.5 KiB
C++
Raw Normal View History

2004-06-29 02:50:07 +00:00
// Boost.Range library
//
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
// distribution is subject to 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)
//
// For more information, see http://www.boost.org/libs/range/
//
#ifndef BOOST_RANGE_BEGIN_HPP
#define BOOST_RANGE_BEGIN_HPP
#if defined(_MSC_VER)
2004-06-29 02:50:07 +00:00
# pragma once
#endif
#include <boost/range/config.hpp>
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
#include <boost/range/detail/begin.hpp>
#else
#include <boost/range/iterator.hpp>
2005-05-30 07:35:51 +00:00
namespace boost
2004-06-29 02:50:07 +00:00
{
2005-03-24 11:23:04 +00:00
2005-05-30 07:35:51 +00:00
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
!BOOST_WORKAROUND(__GNUC__, < 3) \
/**/
namespace range_detail
2004-06-29 02:50:07 +00:00
{
2005-03-24 11:23:04 +00:00
#endif
2005-05-30 07:35:51 +00:00
2004-06-29 02:50:07 +00:00
//////////////////////////////////////////////////////////////////////
2004-08-10 16:05:53 +00:00
// primary template
2004-06-29 02:50:07 +00:00
//////////////////////////////////////////////////////////////////////
2005-05-30 07:35:51 +00:00
2004-06-29 02:50:07 +00:00
template< typename C >
2006-05-18 20:52:17 +00:00
inline BOOST_DEDUCED_TYPENAME range_iterator<C>::type
2007-10-24 15:19:16 +00:00
range_begin( C& c )
2004-06-29 02:50:07 +00:00
{
2007-11-17 20:22:05 +00:00
//
// If you get a compile-error here, it is most likely because
// you have not implemented range_begin() properly in
// the namespace of C
//
2005-05-30 07:35:51 +00:00
return c.begin();
2004-06-29 02:50:07 +00:00
}
2005-05-30 07:35:51 +00:00
2004-06-29 02:50:07 +00:00
//////////////////////////////////////////////////////////////////////
// pair
//////////////////////////////////////////////////////////////////////
2005-05-30 07:35:51 +00:00
2004-06-29 02:50:07 +00:00
template< typename Iterator >
2007-10-24 15:19:16 +00:00
inline Iterator range_begin( const std::pair<Iterator,Iterator>& p )
2004-06-29 02:50:07 +00:00
{
return p.first;
}
2005-05-30 07:35:51 +00:00
2004-06-29 02:50:07 +00:00
template< typename Iterator >
2007-10-24 15:19:16 +00:00
inline Iterator range_begin( std::pair<Iterator,Iterator>& p )
2004-06-29 02:50:07 +00:00
{
return p.first;
}
2005-05-30 07:35:51 +00:00
2004-06-29 02:50:07 +00:00
//////////////////////////////////////////////////////////////////////
// array
//////////////////////////////////////////////////////////////////////
2005-05-30 07:35:51 +00:00
2006-05-18 20:52:17 +00:00
//
// May this be discarded? Or is it needed for bad compilers?
//
2004-06-29 02:50:07 +00:00
template< typename T, std::size_t sz >
2008-06-12 10:54:44 +00:00
inline const T* range_begin( const T (&a)[sz] )
2004-06-29 02:50:07 +00:00
{
2008-06-12 10:54:44 +00:00
return a;
2004-06-29 02:50:07 +00:00
}
2005-05-30 07:35:51 +00:00
2004-06-29 02:50:07 +00:00
template< typename T, std::size_t sz >
2008-06-12 10:54:44 +00:00
inline T* range_begin( T (&a)[sz] )
2004-06-29 02:50:07 +00:00
{
2008-06-12 10:54:44 +00:00
return a;
2004-06-29 02:50:07 +00:00
}
2005-05-30 07:35:51 +00:00
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
!BOOST_WORKAROUND(__GNUC__, < 3) \
/**/
2004-08-16 22:07:07 +00:00
} // namespace 'range_detail'
2005-03-24 11:23:04 +00:00
#endif
2004-06-29 02:50:07 +00:00
// Use a ADL namespace barrier to avoid ambiguity with other unqualified
// calls. This is particularly important with C++0x encouraging
// unqualified calls to begin/end.
namespace range_adl_barrier
{
2004-08-10 16:05:53 +00:00
template< class T >
2006-05-18 20:52:17 +00:00
inline BOOST_DEDUCED_TYPENAME range_iterator<T>::type begin( T& r )
2004-08-10 16:05:53 +00:00
{
2005-05-30 07:35:51 +00:00
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
!BOOST_WORKAROUND(__GNUC__, < 3) \
/**/
using namespace range_detail;
#endif
2007-10-24 15:19:16 +00:00
return range_begin( r );
2004-08-10 16:05:53 +00:00
}
template< class T >
2006-05-18 20:52:17 +00:00
inline BOOST_DEDUCED_TYPENAME range_iterator<const T>::type begin( const T& r )
2004-08-10 16:05:53 +00:00
{
2005-05-30 07:35:51 +00:00
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
!BOOST_WORKAROUND(__GNUC__, < 3) \
/**/
using namespace range_detail;
#endif
2007-10-24 15:19:16 +00:00
return range_begin( r );
2004-09-21 19:19:12 +00:00
}
} // namespace range_adl_barrier
2004-06-29 02:50:07 +00:00
} // namespace boost
2005-05-30 07:35:51 +00:00
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
2004-06-29 02:50:07 +00:00
2004-09-16 18:21:42 +00:00
namespace boost
{
namespace range_adl_barrier
2004-09-16 18:21:42 +00:00
{
template< class T >
inline BOOST_DEDUCED_TYPENAME range_iterator<const T>::type
const_begin( const T& r )
{
return boost::range_adl_barrier::begin( r );
}
} // namespace range_adl_barrier
using namespace range_adl_barrier;
} // namespace boost
2004-09-16 18:21:42 +00:00
2004-06-29 02:50:07 +00:00
#endif
2006-05-18 20:52:17 +00:00