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

📄 associative_range.hpp

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 HPP
📖 第 1 页 / 共 2 页
字号:
/* /////////////////////////////////////////////////////////////////////////
 * File:        rangelib/associative_range.hpp
 *
 * Purpose:     Associative container range adaptor.
 *
 * Created:     1st October 2004
 * Updated:     10th June 2006
 *
 * Home:        http://stlsoft.org/
 *
 * Copyright (c) 2004-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/associative_range.hpp Sequence container range adaptor */

#ifndef RANGELIB_INCL_RANGELIB_HPP_ASSOCIATIVE_RANGE
#define RANGELIB_INCL_RANGELIB_HPP_ASSOCIATIVE_RANGE

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define RANGELIB_VER_RANGELIB_HPP_ASSOCIATIVE_RANGE_MAJOR       1
# define RANGELIB_VER_RANGELIB_HPP_ASSOCIATIVE_RANGE_MINOR       4
# define RANGELIB_VER_RANGELIB_HPP_ASSOCIATIVE_RANGE_REVISION    1
# define RANGELIB_VER_RANGELIB_HPP_ASSOCIATIVE_RANGE_EDIT        20
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

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

/*
[Incompatibilies-start]
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 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_HPP_ITERATOR
# include <stlsoft/iterator.hpp>      // for discrimination of the MSVC Dinkumware libs (with the bad member types)
#endif /* !STLSOFT_INCL_STLSOFT_HPP_ITERATOR */
#if defined(STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED)
 // This stuff's needed for type fixing 'referent_type' => 'mapped_type'
# ifndef STLSOFT_INCL_STLSOFT_META_HPP_MEMBER_TRAITS
#  include <stlsoft/meta/member_traits.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_META_HPP_MEMBER_TRAITS */
# ifndef STLSOFT_INCL_STLSOFT_HPP_ASSOCIATIVE_MAPPED_TYPE_DETECTOR
#  include <stlsoft/associative_mapped_type_detector.hpp>
# endif /* !STLSOFT_INCL_STLSOFT_HPP_ASSOCIATIVE_MAPPED_TYPE_DETECTOR */
#else /* ? STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED */
# if defined(STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_VC)
#  if STLSOFT_CF_STD_LIBRARY_DINKUMWARE_VC_VERSION <= STLSOFT_CF_DINKUMWARE_VC_VERSION_6_0
#   pragma message("associative_range<> assumes that the adapted type has a 'mapped_type' member type. std::map in the Dinkumware library that ships with Visual C++ 5 & 6 uses the non-standard 'referent_type', so adapting a parameterisation of it will not compile")
#  endif /* STLSOFT_CF_STD_LIBRARY_DINKUMWARE_VC_VERSION <= STLSOFT_CF_DINKUMWARE_VC_VERSION_6_0 */
# endif /* STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_VC */
#endif /* STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED */

#ifdef STLSOFT_UNITTEST
# include <algorithm>
# include <map>
# include <numeric>
#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 associative container types
template<   ss_typename_param_k S
        ,   bool                B_CONST
        >
struct associative_range_traits
{
public:
    /// The associative type
    typedef S                                                       associative_type;
    /// The associative reference type
    typedef S                                                       &associative_reference_type;
    /// The key type
    typedef ss_typename_type_k associative_type::key_type           key_type;
    /// The mapped type
    typedef ss_typename_type_k associative_mapped_type_detector<S>::mapped_type mapped_type;
    /// The value type
    typedef ss_typename_type_k associative_type::value_type         value_type;
    /// The mutating (non-const) iterator type
    typedef ss_typename_type_k select_first_type_if<   ss_typename_type_k associative_type::const_iterator
                                                ,   ss_typename_type_k associative_type::iterator
                                                ,   B_CONST
                                                >::type             iterator;
    /// The non-mutating (const) iterator type
    typedef ss_typename_type_k associative_type::const_iterator     const_iterator;
    /// The mutating (non-const) reference type
    typedef ss_typename_type_k select_first_type_if<   ss_typename_type_k associative_type::const_reference
                                                ,   ss_typename_type_k associative_type::reference
                                                ,   B_CONST
                                                >::type             reference;
    /// The non-mutating (const) reference type
    typedef ss_typename_type_k associative_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 associative_type::difference_type    difference_type;
    /// The size type
    typedef ss_typename_type_k associative_type::size_type          size_type;
};

template<   ss_typename_param_k S
        >
struct associative_range_traits<S, true>
{
public:
    typedef S                                                       associative_type;
    typedef S                                                       &associative_reference_type;
    typedef ss_typename_type_k associative_type::key_type           key_type;
    typedef ss_typename_type_k associative_mapped_type_detector<S>::mapped_type mapped_type;
//    typedef ss_typename_type_k associative_type::referent_type      mapped_type;
    typedef ss_typename_type_k associative_type::value_type         value_type;
    typedef ss_typename_type_k associative_type::const_iterator     iterator;
    typedef ss_typename_type_k associative_type::const_iterator     const_iterator;
    typedef ss_typename_type_k associative_type::const_reference    reference;
    typedef ss_typename_type_k associative_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 associative_type::difference_type    difference_type;
    typedef ss_typename_type_k associative_type::size_type          size_type;
};

#else /* ? STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED */

template<   ss_typename_param_k S
        >
struct associative_range_traits
{
public:
    typedef S                                                       associative_type;
    typedef S                                                       &associative_reference_type;
    typedef ss_typename_type_k associative_type::key_type           key_type;
    typedef ss_typename_type_k associative_type::mapped_type        mapped_type;
    typedef ss_typename_type_k associative_type::value_type         value_type;
    typedef ss_typename_type_k associative_type::iterator           iterator;
    typedef ss_typename_type_k associative_type::const_iterator     const_iterator;
    typedef ss_typename_type_k associative_type::reference          reference;
    typedef ss_typename_type_k associative_type::const_reference    const_reference;
    typedef ss_typename_type_k associative_type::difference_type    difference_type;
    typedef ss_typename_type_k associative_type::size_type          size_type;
};

template<   ss_typename_param_k S
        >
struct associative_range_traits_dinkumware_early
{
public:
    typedef S                                                       associative_type;
    typedef S                                                       &associative_reference_type;
    typedef ss_typename_type_k associative_type::key_type           key_type;
    typedef ss_typename_type_k associative_type::referent_type      mapped_type;
    typedef ss_typename_type_k associative_type::value_type         value_type;
    typedef ss_typename_type_k associative_type::iterator           iterator;
    typedef ss_typename_type_k associative_type::const_iterator     const_iterator;
    typedef ss_typename_type_k associative_type::reference          reference;
    typedef ss_typename_type_k associative_type::const_reference    const_reference;
    typedef ss_typename_type_k associative_type::difference_type    difference_type;
    typedef ss_typename_type_k associative_type::size_type          size_type;
};

template<   ss_typename_param_k S
        >
struct const_associative_range_traits
{
public:
    typedef S                                                       associative_type;
    typedef S const                                                 &associative_reference_type;
    typedef ss_typename_type_k associative_type::key_type           key_type;
    typedef ss_typename_type_k associative_type::mapped_type        mapped_type;
    typedef ss_typename_type_k associative_type::value_type         value_type;
    typedef ss_typename_type_k associative_type::const_iterator     iterator;
    typedef ss_typename_type_k associative_type::const_iterator     const_iterator;
    typedef ss_typename_type_k associative_type::const_reference    reference;
    typedef ss_typename_type_k associative_type::const_reference    const_reference;
    typedef ss_typename_type_k associative_type::difference_type    difference_type;
    typedef ss_typename_type_k associative_type::size_type          size_type;
};

template<   ss_typename_param_k S
        >
struct const_associative_range_traits_dinkumware_early
{
public:
    typedef S                                                       associative_type;
    typedef S const                                                 &associative_reference_type;
    typedef ss_typename_type_k associative_type::key_type           key_type;
    typedef ss_typename_type_k associative_type::referent_type      mapped_type;
    typedef ss_typename_type_k associative_type::value_type         value_type;
    typedef ss_typename_type_k associative_type::const_iterator     iterator;
    typedef ss_typename_type_k associative_type::const_iterator     const_iterator;

⌨️ 快捷键说明

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