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

📄 adapted_iterator_traits.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 2 页
字号:
    ///
    /// This is the member <code>pointer</code> of the adapted iterator type, if it is defined. If not, it is defined to
    /// be <code>void</code>, so as to prevent any dangerous use of it. This will likely act as a compile-time constraint
    /// to prevent the base iterator type being adapted (which is nice).
    typedef ss_typename_type_k select_first_type_if<putative_pointer_
                                                ,   void
                                                ,   HAS_MEMBER_POINTER || IS_DINKUMWARE_OLD_FORM
                                                >::type                                 pointer;

//private:
//    enum { is_const           =   0 != member_traits<pointer>::is_const                                   };

public:
    /// \brief The reference type
    ///
    /// This is the member <code>reference</code> of the adapted iterator type, if it is defined. If not, it is defined to
    /// be <code>void</code>, so as to prevent any dangerous use of it. This will likely act as a compile-time constraint
    /// to prevent the base iterator type being adapted (which is nice).
    typedef ss_typename_type_k select_first_type_if<putative_reference_
                                                ,   void
                                                ,   HAS_MEMBER_REFERENCE || IS_DINKUMWARE_OLD_FORM
                                                >::type                                 reference;
private:
    // Here's where it gets super-tricky, since we need to work out the const_pointer and const_reference types,
    // and define them in the cases that:
    //
    // value_type is void     - Reference Category: Void
    // pointer is void        - Reference Category: By-Value Temporary
    // pointer is a pointer   - Reference Category: > By-Value Temporary

    public:
    enum { REF_CAT_IS_VOID          =   0 != is_same_type<value_type, void>::value && (0 == IS_DINKUMWARE_OLD_FORM)                         };
    enum { REF_CAT_IS_BVT           =   0 == REF_CAT_IS_VOID && 0 != is_same_type<pointer, void>::value && (0 == IS_DINKUMWARE_OLD_FORM)    };
    private:

    ~adapted_iterator_traits()
    {
        void    (*p)()  =   constraints;

        STLSOFT_SUPPRESS_UNUSED(p);
    }

// This has to be non-private, otherwise GCC cries me a river
protected:
    static void constraints()
    {
        // If this fires, then the adapted iterator defines one, but not both, of pointer & reference, or defines
        // them inconsistenly (i.e. one is void, but not both)
        STLSOFT_STATIC_ASSERT((is_same_type<pointer, void>::value == is_same_type<reference, void>::value));
    }
private:

    // The base type
    typedef ss_typename_type_k base_type_traits<pointer>::base_type                     pointer_base_type_;
    typedef ss_typename_type_k base_type_traits<reference>::base_type                   reference_base_type_;

    // Work out what const_pointer will be:
    //
    // - if REF_CAT_IS_VOID, then it's void
    // - if REF_CAT_IS_BVT, then it's void
    // - if higher ref cat, then it's base_type_traits<pointer>::base_type const*


public:
    /// \brief The const_pointer type
    ///
    /// This is either void, if the iterator element reference category is <b>Void</b> or <b>BVT</b>, otherwise
    /// it's <code>"<i>value_type</i>" const*</code>, where <code>"<i>value_type</i>"</code> is the
    /// deduced value type obtained from <code>pointer</code>.
    typedef ss_typename_type_k select_first_type_if<void
                                                ,   pointer_base_type_ const*
                                                ,   REF_CAT_IS_VOID || REF_CAT_IS_BVT
                                                >::type                                 const_pointer;

    /// \brief The const_reference type
    ///
    /// This is either void, if the iterator element reference category is <b>Void</b> or <b>BVT</b>, otherwise
    /// it's <code>"<i>value_type</i>" const*</code>, where <code>"<i>value_type</i>"</code> is the
    /// deduced value type obtained from <code>reference</code>.
    typedef ss_typename_type_k select_first_type_if<void
                                                ,   ss_typename_type_k add_const_ref<reference_base_type_>::type
                                                ,   REF_CAT_IS_VOID || REF_CAT_IS_BVT
                                                >::type                                 const_reference;

public:
    /// \brief The effective reference type
    ///
    /// If the base iterator element reference category is <b>Transient</b> or higher, then this is
    /// the reference member of the base iterator. Otherwise, if the reference category is <b>BVT</b>
    /// then this is value_type. Otherwise (if the reference category is <b>Void</b>), then this is void
    typedef ss_typename_type_k select_first_type_if<value_type
                                                ,   reference
                                                ,   REF_CAT_IS_BVT
                                                >::type                                 effective_reference;
    /// \brief The effective const_reference type
    ///
    /// If the base iterator element reference category is <b>Transient</b> or higher, then this is
    /// const_reference. Otherwise, if the reference category is <b>BVT</b> then this is value_type. Otherwise
    /// (if the reference category is <b>Void</b>), then this is void
    typedef ss_typename_type_k select_first_type_if<ss_typename_type_k add_const<value_type>::type
                                                ,   const_reference
                                                ,   REF_CAT_IS_BVT
                                                >::type                                 effective_const_reference;

    /// \brief The effective pointer type
    ///
    /// If the base iterator element pointer category is <b>Transient</b> or higher, then this is
    /// the pointer member of the base iterator. Otherwise, if the pointer category is <b>BVT</b>
    /// then this is void. Otherwise (if the pointer category is <b>Void</b>), then this is void
    typedef ss_typename_type_k select_first_type_if<void
                                                ,   pointer
                                                ,   REF_CAT_IS_BVT
                                                >::type                                 effective_pointer;
    /// \brief The effective const_pointer type
    ///
    /// If the base iterator element pointer category is <b>Transient</b> or higher, then this is
    /// const_pointer. Otherwise, if the pointer category is <b>BVT</b> then this is void. Otherwise
    /// (if the pointer category is <b>Void</b>), then this is void
    typedef ss_typename_type_k select_first_type_if<void
                                                ,   const_pointer
                                                ,   REF_CAT_IS_BVT
                                                >::type                                 effective_const_pointer;
};

# ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

template <ss_typename_param_k T>
struct adapted_iterator_traits<T*>
{
    typedef stlsoft_ns_qual_std(random_access_iterator_tag) iterator_category;
    typedef T                                               value_type;
    typedef ss_ptrdiff_t                                    difference_type;
    typedef value_type                                      *pointer;
    typedef value_type const                                *const_pointer;
    typedef value_type                                      &reference;
    typedef value_type const                                &const_reference;
    typedef reference                                       effective_reference;
    typedef const_reference                                 effective_const_reference;
    typedef pointer                                         effective_pointer;
    typedef const_pointer                                   effective_const_pointer;
};

template <ss_typename_param_k T>
struct adapted_iterator_traits<T const*>
{
    typedef stlsoft_ns_qual_std(random_access_iterator_tag) iterator_category;
    typedef T                                               value_type;
    typedef ss_ptrdiff_t                                    difference_type;
    typedef value_type const                                *pointer;
    typedef value_type const                                *const_pointer;
    typedef value_type const                                &reference;
    typedef value_type const                                &const_reference;
    typedef reference                                       effective_reference;
    typedef const_reference                                 effective_const_reference;
    typedef pointer                                         effective_pointer;
    typedef const_pointer                                   effective_const_pointer;
};

template <ss_typename_param_k T>
struct adapted_iterator_traits<T volatile*>
{
    typedef stlsoft_ns_qual_std(random_access_iterator_tag) iterator_category;
    typedef T                                               value_type;
    typedef ss_ptrdiff_t                                    difference_type;
    typedef value_type volatile                             *pointer;
    typedef value_type volatile const                       *const_pointer;
    typedef value_type volatile                             &reference;
    typedef value_type volatile const                       &const_reference;
    typedef reference                                       effective_reference;
    typedef const_reference                                 effective_const_reference;
    typedef pointer                                         effective_pointer;
    typedef const_pointer                                   effective_const_pointer;
};

template <ss_typename_param_k T>
struct adapted_iterator_traits<T const volatile*>
{
    typedef stlsoft_ns_qual_std(random_access_iterator_tag) iterator_category;
    typedef T                                               value_type;
    typedef ss_ptrdiff_t                                    difference_type;
    typedef value_type volatile const                       *pointer;
    typedef value_type volatile const                       *const_pointer;
    typedef value_type volatile const                       &reference;
    typedef value_type volatile const                       &const_reference;
    typedef reference                                       effective_reference;
    typedef const_reference                                 effective_const_reference;
    typedef pointer                                         effective_pointer;
    typedef const_pointer                                   effective_const_pointer;
};

# endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

#else /* ? STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */

#endif /* STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT */

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

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

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

#endif /* !STLSOFT_INCL_STLSOFT_ITERATORS_HPP_ADAPTED_ITERATOR_TRAITS */

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

⌨️ 快捷键说明

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