📄 iterator_range.hpp
字号:
/* /////////////////////////////////////////////////////////////////////////
* File: rangelib/iterator_range.hpp
*
* Purpose: Iterator range adaptor.
*
* Created: 4th November 2003
* Updated: 10th June 2006
*
* Home: http://stlsoft.org/
*
* Copyright (c) 2003-2006, Matthew Wilson and Synesis Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
* any contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////// */
/** \file rangelib/iterator_range.hpp Iterator range adaptor */
#ifndef RANGELIB_INCL_RANGELIB_HPP_ITERATOR_RANGE
#define RANGELIB_INCL_RANGELIB_HPP_ITERATOR_RANGE
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define RANGELIB_VER_RANGELIB_HPP_ITERATOR_RANGE_MAJOR 2
# define RANGELIB_VER_RANGELIB_HPP_ITERATOR_RANGE_MINOR 6
# define RANGELIB_VER_RANGELIB_HPP_ITERATOR_RANGE_REVISION 1
# define RANGELIB_VER_RANGELIB_HPP_ITERATOR_RANGE_EDIT 31
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Auto-generation and compatibility
*/
/*
[<[STLSOFT-AUTO:NO-UNITTEST]>]
[Incompatibilies-start]
STLSOFT_COMPILER_IS_BORLAND:
STLSOFT_COMPILER_IS_GCC: __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
STLSOFT_COMPILER_IS_MSVC: _MSC_VER < 1200
STLSOFT_COMPILER_IS_MWERKS: (__MWERKS__ & 0xFF00) < 0x3000
[Incompatibilies-end]
*/
/* /////////////////////////////////////////////////////////////////////////
* Includes
*/
#ifndef RANGELIB_INCL_RANGELIB_HPP_RANGELIB
# include <rangelib/rangelib.hpp>
#endif /* !RANGELIB_INCL_RANGELIB_HPP_RANGELIB */
#ifndef STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
# error rangelib/iterator_range.hpp is not compatible with compilers that do not support partial template specialisation
#endif /* !STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */
#ifndef RANGELIB_INCL_RANGELIB_HPP_RANGE_CATEGORIES
# include <rangelib/range_categories.hpp>
#endif /* !RANGELIB_INCL_RANGELIB_HPP_RANGE_CATEGORIES */
#ifndef STLSOFT_INCL_STLSOFT_HPP_OPERATOR_BOOL
# include <stlsoft/operator_bool.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_HPP_OPERATOR_BOOL */
#ifndef STLSOFT_INCL_STLSOFT_HPP_META
# include <stlsoft/meta.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_HPP_META */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_BASE_TYPE_TRAITS
# include <stlsoft/meta/base_type_traits.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_BASE_TYPE_TRAITS */
#ifndef STLSOFT_INCL_STLSOFT_HPP_ITERATOR
# include <stlsoft/iterator.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_HPP_ITERATOR */
#ifdef STLSOFT_UNITTEST
# include <algorithm>
# include <deque>
# include <list>
# include <numeric>
# include <vector>
#endif /* STLSOFT_UNITTEST */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*/
#ifndef RANGELIB_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
/* There is no stlsoft namespace, so must define ::rangelib */
namespace rangelib
{
# else
/* Define stlsoft::rangelib_project */
namespace stlsoft
{
namespace rangelib_project
{
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !RANGELIB_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Classes
*/
#ifdef STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
/// Traits class for determining the attributes of range-adapted iterator types
template< ss_typename_param_k I
, bool B_CONST
>
struct iterator_range_traits
{
public:
/// The iterator type
typedef I iterator_type;
/// The value type
typedef ss_typename_type_k I::value_type value_type;
private:
#ifdef STLSOFT_ITERATOR_ITERATOR_FORM2_SUPPORT
// Use the iterator itself to determine whether the iterator is const
enum { is_const = base_type_traits<value_type>::is_const };
#else /* ? STLSOFT_ITERATOR_ITERATOR_FORM2_SUPPORT */
// 1. Use iterator_traits ...
typedef std::iterator_traits<I> traits_type_;
// ... to get the pointer type ...
typedef ss_typename_type_k traits_type_::pointer pointer_type_;
// ... to determine whether the iterator is const
enum { is_const = base_type_traits<pointer_type_>::is_const };
#endif /* !STLSOFT_ITERATOR_ITERATOR_FORM2_SUPPORT */
// 2. Use Determine the base type of the value_type, which may then be used to create a reference of the appropriate type
typedef ss_typename_type_k base_type_traits<value_type>::base_type base_value_type;
// enum { is_const = is_const<pointer>::value };
public:
/// The mutating (non-const) iterator type
typedef I iterator;
/// The non-mutating (const) iterator type
typedef ss_typename_type_k base_type_traits<iterator>::base_type const &const_iterator;
/// The mutating (non-const) refernce type
typedef ss_typename_type_k select_first_type_if< base_value_type const &
, base_value_type &, is_const>::type reference;
/// The non-mutating (const) reference type
typedef base_value_type const &const_reference;
// TODO: Stick in the member-finder stuff here, so can assume ptrdiff_t if none found
/// The difference type
typedef ss_typename_type_k iterator_type::difference_type difference_type;
/// The size type
typedef ss_typename_type_k iterator_type::size_type size_type;
};
# ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template< ss_typename_param_k T
, bool B_CONST
>
struct iterator_range_traits<T*, B_CONST>
{
typedef T value_type;
typedef value_type *iterator;
typedef value_type const *const_iterator;
typedef value_type &reference;
typedef value_type const &const_reference;
};
template< ss_typename_param_k T
, bool B_CONST
>
struct iterator_range_traits<T const*, B_CONST>
{
typedef T value_type;
typedef value_type const *iterator;
typedef value_type const *const_iterator;
typedef value_type const &reference;
typedef value_type const &const_reference;
};
# endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
#else /* ? STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */
template< ss_typename_param_k I
>
struct iterator_range_traits
{
public:
typedef I iterator_type;
typedef ss_typename_type_k iterator_type::value_type value_type;
typedef ss_typename_type_k iterator_type::iterator iterator;
typedef ss_typename_type_k iterator_type::const_iterator const_iterator;
typedef ss_typename_type_k iterator_type::reference reference;
typedef ss_typename_type_k iterator_type::const_reference const_reference;
// TODO: Stick in the member-finder stuff here, so can assume ptrdiff_t if none found
typedef ss_typename_type_k iterator_type::difference_type difference_type;
typedef ss_typename_type_k iterator_type::size_type size_type;
};
template< ss_typename_param_k I
>
struct const_iterator_range_traits
{
public:
typedef I iterator_type;
typedef ss_typename_type_k iterator_type::value_type value_type;
typedef ss_typename_type_k iterator_type::const_iterator iterator;
typedef ss_typename_type_k iterator_type::const_iterator const_iterator;
typedef ss_typename_type_k iterator_type::const_reference reference;
typedef ss_typename_type_k iterator_type::const_reference const_reference;
typedef ss_typename_type_k iterator_type::difference_type difference_type;
typedef ss_typename_type_k iterator_type::size_type size_type;
};
template< ss_typename_param_k T
>
struct pointer_iterator_range_traits
{
typedef T value_type;
typedef T *iterator;
typedef T const *const_iterator;
typedef T &reference;
typedef T const &const_reference;
typedef ptrdiff_t difference_type;
typedef size_t size_type;
};
template< ss_typename_param_k T
>
struct const_pointer_iterator_range_traits
{
typedef T value_type;
typedef T const *iterator;
typedef T const *const_iterator;
typedef T const &reference;
typedef T const &const_reference;
typedef ptrdiff_t difference_type;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -