sequence_range.hpp

来自「用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、W」· HPP 代码 · 共 506 行 · 第 1/2 页

HPP
506
字号
/* /////////////////////////////////////////////////////////////////////////
 * File:        rangelib/sequence_range.hpp
 *
 * Purpose:     Sequence container range adaptor.
 *
 * Created:     4th November 2003
 * Updated:     10th June 2006
 *
 * Thanks:      To Luoyi (whom I could not thank by email), for pointing out
 *              some gaps with the sequence_range
 *
 * 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/sequence_range.hpp Sequence container range adaptor */

#ifndef RANGELIB_INCL_RANGELIB_HPP_SEQUENCE_RANGE
#define RANGELIB_INCL_RANGELIB_HPP_SEQUENCE_RANGE

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define RANGELIB_VER_RANGELIB_HPP_SEQUENCE_RANGE_MAJOR    2
# define RANGELIB_VER_RANGELIB_HPP_SEQUENCE_RANGE_MINOR    11
# define RANGELIB_VER_RANGELIB_HPP_SEQUENCE_RANGE_REVISION 1
# define RANGELIB_VER_RANGELIB_HPP_SEQUENCE_RANGE_EDIT     52
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* /////////////////////////////////////////////////////////////////////////
 * Auto-generation and compatibility
 */

/*
[Incompatibilies-start]
STLSOFT_COMPILER_IS_DMC:
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 RANGELIB_INCL_RANGELIB_HPP_RANGE_CATEGORIES
# include <rangelib/range_categories.hpp>
#endif /* !RANGELIB_INCL_RANGELIB_HPP_RANGE_CATEGORIES */
#ifndef RANGELIB_INCL_RANGELIB_HPP_OPERATOR_ADAPTORS
# include <rangelib/operator_adaptors.hpp>
#endif /* !RANGELIB_INCL_RANGELIB_HPP_OPERATOR_ADAPTORS */
#ifndef STLSOFT_INCL_STLSOFT_HPP_META
# include <stlsoft/meta.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_HPP_META */
#ifdef STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED
# ifndef STLSOFT_INCL_STLSOFT_TYPEFIXER_HPP_DIFFERENCE_TYPE
#  include <stlsoft/typefixer/difference_type.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_TYPEFIXER_HPP_DIFFERENCE_TYPE */
# ifndef STLSOFT_INCL_STLSOFT_TYPEFIXER_HPP_REFERENCE
#  include <stlsoft/typefixer/reference.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_TYPEFIXER_HPP_REFERENCE */
# ifndef STLSOFT_INCL_STLSOFT_TYPEFIXER_HPP_ITERATOR
#  include <stlsoft/typefixer/iterator.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_TYPEFIXER_HPP_ITERATOR */
# ifndef STLSOFT_INCL_STLSOFT_TYPEFIXER_HPP_POINTER
#  include <stlsoft/typefixer/pointer.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_TYPEFIXER_HPP_POINTER */
# ifndef STLSOFT_INCL_STLSOFT_META_HPP_MEMBER_TRAITS
#  include <stlsoft/meta/member_traits.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_META_HPP_MEMBER_TRAITS */
#endif /* STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED */

#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
 */

#if defined(STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED)

/// Traits class for determining the attributes of range-adapted sequence container types
template<   ss_typename_param_k S
        ,   bool                B_CONST = false
        >
struct sequence_range_traits
{
private:
    /// Indicates whether the parameterising sequence type has a \c reference member
    ///
    /// \note We can't use the type fixer in a fully correct way here, because
    /// most compilers do not detect reference / const_reference members, so we
    /// take a guess and use the presence/absence of the iterator membertype as
    /// the sign of the presence of the reference member type.
#if defined(STLSOFT_COMPILER_IS_MWERKS)
    enum { HAS_MEMBER_REFERENCE         =   0 != member_traits<S>::has_member_reference         };
    enum { HAS_MEMBER_CONST_REFERENCE   =   0 != member_traits<S>::has_member_const_reference   };
#else /* ? compiler */
    enum { HAS_MEMBER_REFERENCE         =   0 != member_traits<S>::has_member_iterator          };
    enum { HAS_MEMBER_CONST_REFERENCE   =   0 != member_traits<S>::has_member_const_iterator    };
#endif /* compiler */
    enum { HAS_MEMBER_ITERATOR          =   0 != member_traits<S>::has_member_iterator          };  // Need to do these as member enums, otherwise GCC2.95 cries a river
    enum { HAS_MEMBER_CONST_ITERATOR    =   0 != member_traits<S>::has_member_const_iterator    };  // Need to do these as member enums, otherwise GCC2.95 cries a river
    enum { HAS_MEMBER_DIFFERENCE_TYPE   =   0 != member_traits<S>::has_member_difference_type   };  // Need to do these as member enums, otherwise GCC2.95 cries a river
    enum { HAS_MEMBER_POINTER           =   0 != member_traits<S>::has_member_pointer           };
    enum { HAS_MEMBER_CONST_POINTER     =   0 != member_traits<S>::has_member_const_pointer     };

public:
    /// The sequence type
    typedef S                                                       sequence_type;
    /// The sequence reference type
    typedef S                                                       &sequence_reference_type;
    /// The value type
    typedef ss_typename_type_k sequence_type::value_type            value_type;
    /// The mutating (non-const) iterator type
    typedef ss_typename_type_k select_first_type_if<ss_typename_type_k ::stlsoft::typefixer::fixer_iterator<S, HAS_MEMBER_ITERATOR>::iterator
                                                ,   ss_typename_type_k ::stlsoft::typefixer::fixer_const_iterator<S, HAS_MEMBER_CONST_ITERATOR>::const_iterator
                                                ,   HAS_MEMBER_ITERATOR
                                                >::type             iterator;
    /// The non-mutating (const) iterator type
    typedef ss_typename_type_k ::stlsoft::typefixer::fixer_const_iterator<S, HAS_MEMBER_CONST_ITERATOR>::const_iterator
                                                                    const_iterator;
    /// The mutating (non-const) reference type
    typedef ss_typename_type_k select_first_type_if<ss_typename_type_k ::stlsoft::typefixer::fixer_reference<sequence_type, HAS_MEMBER_REFERENCE>::reference
                                                ,   ss_typename_type_k ::stlsoft::typefixer::fixer_const_reference<sequence_type, HAS_MEMBER_CONST_REFERENCE>::const_reference
                                                ,   HAS_MEMBER_REFERENCE
                                                >::type             reference;
    /// The non-mutating (const) reference type
    typedef ss_typename_type_k ::stlsoft::typefixer::fixer_const_reference<S, HAS_MEMBER_CONST_REFERENCE>::const_reference
                                                                    const_reference;
    /// The mutating (non-const) pointer type
    typedef ss_typename_type_k select_first_type_if<ss_typename_type_k ::stlsoft::typefixer::fixer_pointer<sequence_type, HAS_MEMBER_POINTER>::pointer
                                                ,   ss_typename_type_k ::stlsoft::typefixer::fixer_const_pointer<sequence_type, HAS_MEMBER_CONST_POINTER>::const_pointer
                                                ,   HAS_MEMBER_POINTER
                                                >::type             pointer;
    /// The non-mutating (const) pointer type
    typedef ss_typename_type_k ::stlsoft::typefixer::fixer_const_pointer<S, HAS_MEMBER_CONST_POINTER>::const_pointer
                                                                    const_pointer;
    /// The difference type
    typedef ss_typename_type_k select_first_type_if<ss_typename_type_k ::stlsoft::typefixer::fixer_difference_type<S, HAS_MEMBER_DIFFERENCE_TYPE>::difference_type
                                                ,   ss_ptrdiff_t
                                                ,   HAS_MEMBER_DIFFERENCE_TYPE
                                                >::type             difference_type;
    /// The size type
    typedef ss_typename_type_k sequence_type::size_type             size_type;
};

/// Partial specialisation for constant sequences
template<   ss_typename_param_k S
        >
struct sequence_range_traits<S, true>
{
public:
    /// The sequence type
    typedef S                                                       sequence_type;
    /// The sequence reference type
    typedef S                                                       &sequence_reference_type;
    /// The value type
    typedef ss_typename_type_k sequence_type::value_type            value_type;
    /// The mutating (non-const) iterator type
    typedef ss_typename_type_k sequence_type::const_iterator        iterator;
    /// The non-mutating (const) iterator type
    typedef ss_typename_type_k sequence_type::const_iterator        const_iterator;
    /// The non-mutating (const) iterator type
    typedef ss_typename_type_k sequence_type::const_reference       reference;
    /// The non-mutating (const) reference type
    typedef ss_typename_type_k sequence_type::const_reference       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 sequence_type::difference_type       difference_type;
    /// The size type
    typedef ss_typename_type_k sequence_type::size_type             size_type;
};

#else /* ? STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED */

template<   ss_typename_param_k S
        >
struct sequence_range_traits
{
public:
    typedef S                                                       sequence_type;
    typedef S                                                       &sequence_reference_type;
    typedef ss_typename_type_k sequence_type::value_type            value_type;
    typedef ss_typename_type_k sequence_type::iterator              iterator;
    typedef ss_typename_type_k sequence_type::const_iterator        const_iterator;
    typedef ss_typename_type_k sequence_type::reference             reference;
    typedef ss_typename_type_k sequence_type::const_reference       const_reference;
    typedef ss_typename_type_k sequence_type::difference_type       difference_type;
    typedef ss_typename_type_k sequence_type::size_type             size_type;
};

template<   ss_typename_param_k S
        >
struct const_sequence_range_traits
{
public:
    typedef S                                                       sequence_type;

⌨️ 快捷键说明

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