⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index_iterator.hpp

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 HPP
📖 第 1 页 / 共 2 页
字号:
/* /////////////////////////////////////////////////////////////////////////
 * File:        stlsoft/iterators/index_iterator.hpp
 *
 * Purpose:     index_iterator class template.
 *
 * Created:     5th April 2005
 * Updated:     10th June 2006
 *
 * Home:        http://stlsoft.org/
 *
 * Copyright (c) 2005-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 stlsoft/iterators/index_iterator.hpp
///
/// index_iterator class template.

#ifndef STLSOFT_INCL_STLSOFT_ITERATORS_HPP_INDEX_ITERATOR
#define STLSOFT_INCL_STLSOFT_ITERATORS_HPP_INDEX_ITERATOR

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define STLSOFT_VER_STLSOFT_ITERATORS_HPP_INDEX_ITERATOR_MAJOR     1
# define STLSOFT_VER_STLSOFT_ITERATORS_HPP_INDEX_ITERATOR_MINOR     3
# define STLSOFT_VER_STLSOFT_ITERATORS_HPP_INDEX_ITERATOR_REVISION  4
# define STLSOFT_VER_STLSOFT_ITERATORS_HPP_INDEX_ITERATOR_EDIT      17
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* /////////////////////////////////////////////////////////////////////////
 * Compatibility
 */

/*
[Incompatibilies-start]
STLSOFT_COMPILER_IS_BORLAND:
STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1310
STLSOFT_COMPILER_IS_WATCOM:
[Incompatibilies-end]
 */

/* /////////////////////////////////////////////////////////////////////////
 * Includes
 */

#ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
# include <stlsoft/stlsoft.h>
#endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */

#if !defined(STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT)
# error index_iterator cannot be used with compilers that do not support partial template specialisation
#else /* ? STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */
# ifndef STLSOFT_INCL_STLSOFT_ITERATOR_HPP_ADAPTED_ITERATOR_TRAITS
#  include <stlsoft/iterators/adapted_iterator_traits.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_ITERATOR_HPP_ADAPTED_ITERATOR_TRAITS */
# ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_POINTER_TYPE
#  include <stlsoft/meta/is_pointer_type.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_POINTER_TYPE */
# ifndef STLSOFT_INCL_STLSOFT_META_HPP_YESNO
#  include <stlsoft/meta/yesno.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_META_HPP_YESNO */
#endif /* !STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */

/* /////////////////////////////////////////////////////////////////////////
 * Feature discrimination
 */

#ifdef STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
# define STLSOFT_INDEX_ITERATOR_MUTABLE_OP_SUPPORT
#endif /* STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */

#if defined(STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT)
# if !defined(STLSOFT_COMPILER_IS_GCC) || \
     __GNUC__ > 4 || \
     (   __GNUC__ == 3 && \
         __GNUC_MINOR__ >= 4)
#   define STLSOFT_INDEX_ITERATOR_MEM_SEL_OP_SUPPORT
# endif /* compiler */
#endif /* STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */

/* /////////////////////////////////////////////////////////////////////////
 * Namespace
 */

#ifndef _STLSOFT_NO_NAMESPACE
namespace stlsoft
{
#endif /* _STLSOFT_NO_NAMESPACE */

/* ////////////////////////////////////////////////////////////////////// */

/// \weakgroup iterators Iterators
/// \brief STL-compatible iterators

/// \weakgroup adaptors Adaptors
/// \brief Adaptor functions and classes used throughout the STLSoft libraries

/// \weakgroup adaptors_iterator Iterator Adaptors
/// \brief Classes that provide iterator adaptation
/// \ingroup iterators adaptors
/// @{

/* /////////////////////////////////////////////////////////////////////////
 * Classes
 */

template<   ss_typename_param_k I
        ,   ss_typename_param_k T = adapted_iterator_traits<I>
        >
// [[synesis:class:iterator: index_iterator<T<I>>]]
class index_iterator
{
/// \name Member Types
/// @{
private:
    // There are several problems to solve here.
    //
    //  First, the issue of whether the library profers a meaningful definition of
    //  std::iterator_traits for this, or any, iterator type
    //
    //  Second, deducing whether the base iterator is const or not
    //
    //  Third, deducing the element reference category of base iterator type, and
    //  defining the member types accordingly
    //
    // Postscriptum:
    //
    // Thankfully we don't need to worry about that any more, because
    // adapted_iterator_traits handles it all for us. :-)

public:
    typedef I                                                           base_iterator_type;
    typedef T                                                           traits_type;
    typedef index_iterator<I>                                           class_type;
    typedef ss_typename_type_k traits_type::iterator_category           iterator_category;
    typedef ss_typename_type_k traits_type::value_type                  value_type;
    typedef ss_typename_type_k traits_type::pointer                     pointer;
    typedef ss_typename_type_k traits_type::reference                   reference;
    typedef ss_typename_type_k traits_type::difference_type             difference_type;
    typedef ss_typename_type_k traits_type::const_pointer               const_pointer;
    typedef ss_typename_type_k traits_type::const_reference             const_reference;
    typedef ss_typename_type_k traits_type::effective_reference         effective_reference;
    typedef ss_typename_type_k traits_type::effective_const_reference   effective_const_reference;
    typedef ss_ptrdiff_t                                                index_type;
    typedef ss_typename_type_k traits_type::effective_pointer           effective_pointer;
    typedef ss_typename_type_k traits_type::effective_const_pointer     effective_const_pointer;
/// @}

/// \name Construction
/// @{
public:
    index_iterator()
        : m_it(base_iterator_type())
        , m_index(0)
    {}
    ss_explicit_k index_iterator(base_iterator_type it, index_type index = 0)
        : m_it(it)
        , m_index(index)
    {}
    index_iterator(class_type const &rhs)
        : m_it(rhs.m_it)
        , m_index(rhs.m_index)
    {}

    /// \brief A copy of the base iterator
    base_iterator_type  base() const
    {
        return m_it;
    }
/// @}

/// \name Forward Iterator methods
/// @{
public:
    class_type &operator ++()
    {
        ++m_it;
        ++m_index;

        return *this;
    }

    class_type operator ++(int)
    {
        class_type  r(*this);

        operator ++();

        return r;
    }

#ifdef STLSOFT_INDEX_ITERATOR_MUTABLE_OP_SUPPORT
    effective_reference operator *()
    {
        return *m_it;
    }
#endif /* STLSOFT_INDEX_ITERATOR_MUTABLE_OP_SUPPORT */

    effective_const_reference operator *() const
    {
        return *m_it;
    }


#ifdef STLSOFT_INDEX_ITERATOR_MEM_SEL_OP_SUPPORT

#if 0
    effective_pointer operator ->()
    {
        return m_it.operator ->();
    }

    effective_const_pointer operator ->() const
    {
        return m_it.operator ->();
    }
#else /* ? 0 */
# ifdef STLSOFT_INDEX_ITERATOR_MUTABLE_OP_SUPPORT
    effective_pointer operator ->()
    {
        enum { is_iterator_pointer_type = is_pointer_type<base_iterator_type>::value };

        // This has to be a separate typedef, otherwise DMC++ has a fit
        typedef ss_typename_type_k value_to_yesno_type<is_iterator_pointer_type>::type  yesno_t;

        return invoke_member_selection_operator_(yesno_t());
    }
# endif /* STLSOFT_INDEX_ITERATOR_MUTABLE_OP_SUPPORT */

    effective_const_pointer operator ->() const
    {
        enum { is_iterator_pointer_type = is_pointer_type<base_iterator_type>::value };

        // This has to be a separate typedef, otherwise DMC++ has a fit
        typedef ss_typename_type_k value_to_yesno_type<is_iterator_pointer_type>::type  yesno_t;

        return invoke_member_selection_operator_(yesno_t());
    }
#endif /* 0 */

#endif /* STLSOFT_INDEX_ITERATOR_MUTABLE_OP_SUPPORT */
/// @}

/// \name Bidirectional Iterator methods
/// @{
public:
    class_type &operator --()
    {
        --m_it;
        --m_index;

        return *this;
    }

    class_type operator --(int)
    {
        class_type  r(*this);

        operator --();

        return r;
    }
/// @}

/// \name Random-Access Iterator methods
/// @{
public:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -