From 5850d7ce3e3fd328ec66a898176bc7d57bf28229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Thu, 18 May 2006 20:53:21 +0000 Subject: [PATCH] new traits and functions for v2 [SVN r34013] --- include/boost/range/as_array.hpp | 45 +++++++++++ include/boost/range/as_literal.hpp | 120 +++++++++++++++++++++++++++++ include/boost/range/category.hpp | 29 +++++++ include/boost/range/distance.hpp | 34 ++++++++ include/boost/range/pointer.hpp | 29 +++++++ include/boost/range/reference.hpp | 29 +++++++ 6 files changed, 286 insertions(+) create mode 100755 include/boost/range/as_array.hpp create mode 100755 include/boost/range/as_literal.hpp create mode 100755 include/boost/range/category.hpp create mode 100755 include/boost/range/distance.hpp create mode 100755 include/boost/range/pointer.hpp create mode 100755 include/boost/range/reference.hpp diff --git a/include/boost/range/as_array.hpp b/include/boost/range/as_array.hpp new file mode 100755 index 0000000..0723e60 --- /dev/null +++ b/include/boost/range/as_array.hpp @@ -0,0 +1,45 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 2006. 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_AS_ARRAY_HPP +#define BOOST_RANGE_AS_ARRAY_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif + +#include +#include + +namespace boost +{ + + template< class R > + inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + as_array( R& r ) + { + return boost::make_iterator_range( r ); + } + +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + template< class Range > + inline boost::iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + as_array( const Range& r ) + { + return boost::make_iterator_range( r ); + } + +#endif + +} + +#endif + diff --git a/include/boost/range/as_literal.hpp b/include/boost/range/as_literal.hpp new file mode 100755 index 0000000..069f82d --- /dev/null +++ b/include/boost/range/as_literal.hpp @@ -0,0 +1,120 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 2006. 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_DETAIL_AS_LITERAL_HPP +#define BOOST_RANGE_DETAIL_AS_LITERAL_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif + +#if BOOST_NO_FUNCTION_TEMPLATE_ORDERING +#include +#else + +#include +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + inline std::size_t length( const char* s ) + { + return strlen( s ); + } + + inline std::size_t length( const wchar_t* s ) + { + return wcslen( s ); + } + + // + // Remark: the compiler cannot choose between T* and T[sz] + // overloads, so we must put the T* internal to the + // unconstrained version. + // + + inline bool is_char_ptr( char* ) + { + return true; + } + + inline bool is_char_ptr( const char* ) + { + return true; + } + + + inline bool is_char_ptr( wchar_t* ) + { + return true; + } + + inline bool is_char_ptr( const wchar_t* ) + { + return true; + } + + template< class T > + inline long is_char_ptr( T r ) + { + return 0L; + } + + template< class T > + inline iterator_range + make_range( T* const r, bool ) + { + return iterator_range( r, r + length(r) ); + } + + template< class T > + inline iterator_range::type> + make_range( T& r, long ) + { + return boost::make_iterator_range( r ); + } + + } + + template< class Range > + inline iterator_range::type> + as_literal( Range& r ) + { + return range_detail::make_range( r, range_detail::is_char_ptr(r) ); + } + + template< class Range > + inline iterator_range::type> + as_literal( const Range& r ) + { + return range_detail::make_range( r, range_detail::is_char_ptr(r) ); + } + + template< class Char, std::size_t sz > + inline iterator_range as_literal( Char (&arr)[sz] ) + { + return boost::make_iterator_range( arr, arr + sz - 1 ); + } + + + template< class Char, std::size_t sz > + inline iterator_range as_literal( const Char (&arr)[sz] ) + { + return boost::make_iterator_range( arr, arr + sz - 1 ); + } +} + +#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING + +#endif diff --git a/include/boost/range/category.hpp b/include/boost/range/category.hpp new file mode 100755 index 0000000..1574605 --- /dev/null +++ b/include/boost/range/category.hpp @@ -0,0 +1,29 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 2003-2006. 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_CATEGORY_HPP +#define BOOST_RANGE_CATEGORY_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif + +#include +#include +#include + +namespace boost +{ + template< class T > + struct range_category : iterator_category< typename range_iterator::type > + { }; +} + +#endif diff --git a/include/boost/range/distance.hpp b/include/boost/range/distance.hpp new file mode 100755 index 0000000..42a106d --- /dev/null +++ b/include/boost/range/distance.hpp @@ -0,0 +1,34 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 2003-2006. 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_DISTANCE_HPP +#define BOOST_RANGE_DISTANCE_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif + +#include +#include +#include + +namespace boost +{ + + template< class T > + inline BOOST_DEDUCED_TYPENAME range_difference::type + distance( const T& r ) + { + return std::distance( boost::begin( r ), boost::end( r ) ); + } + +} // namespace 'boost' + +#endif diff --git a/include/boost/range/pointer.hpp b/include/boost/range/pointer.hpp new file mode 100755 index 0000000..e7431ff --- /dev/null +++ b/include/boost/range/pointer.hpp @@ -0,0 +1,29 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 2003-2006. 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_POINTER_TYPE_HPP +#define BOOST_RANGE_POINTER_TYPE_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif + +#include +#include +#include + +namespace boost +{ + template< class T > + struct range_pointer : iterator_pointer< typename range_iterator::type > + { }; +} + +#endif diff --git a/include/boost/range/reference.hpp b/include/boost/range/reference.hpp new file mode 100755 index 0000000..d308e43 --- /dev/null +++ b/include/boost/range/reference.hpp @@ -0,0 +1,29 @@ +// 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_REFERENCE_TYPE_HPP +#define BOOST_RANGE_REFERENCE_TYPE_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif + +#include +#include +#include + +namespace boost +{ + template< class T > + struct range_reference : iterator_reference< typename range_iterator::type > + { }; +} + +#endif