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

📄 static_array.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 5 页
字号:
/* /////////////////////////////////////////////////////////////////////////
 * File:        stlsoft/containers/static_array.hpp
 *
 * Purpose:     Statically sized multidimensional class template.
 *
 * Created:     4th August 1998
 * Updated:     8th May 2007
 *
 * Thanks to:   Neal Becker for suggesting the uninitialised mode.
 *
 * Home:        http://stlsoft.org/
 *
 * Copyright (c) 1998-2007, 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/containers/static_array.hpp
 *
 * \brief [C++ only] Definition of the stlsoft::static_array_1d,
 *    stlsoft::static_array_2d, stlsoft::static_array_3d, and
 *    stlsoft::static_array_4d multidimensional array class templates
 *   (\ref group__library__containers "Containers" Library).
 */

#ifndef STLSOFT_INCL_STLSOFT_CONTAINERS_HPP_STATIC_ARRAY
#define STLSOFT_INCL_STLSOFT_CONTAINERS_HPP_STATIC_ARRAY

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define STLSOFT_VER_STLSOFT_CONTAINERS_HPP_STATIC_ARRAY_MAJOR     4
# define STLSOFT_VER_STLSOFT_CONTAINERS_HPP_STATIC_ARRAY_MINOR     3
# define STLSOFT_VER_STLSOFT_CONTAINERS_HPP_STATIC_ARRAY_REVISION  5
# define STLSOFT_VER_STLSOFT_CONTAINERS_HPP_STATIC_ARRAY_EDIT      181
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

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

/*
[Incompatibilies-start]
STLSOFT_COMPILER_IS_BORLAND:  __BORLANDC__<0x0564
STLSOFT_COMPILER_IS_DMC:  __DMC__<0x0844
STLSOFT_COMPILER_IS_GCC:  __GNUC__<3
STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1200
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_COMPILER_IS_BORLAND) && \
    __BORLANDC__ < 0x0560
# error stlsoft/containers/static_array.hpp is not compatible with Borland C/C++ prior to 5.6
#elif defined(STLSOFT_COMPILER_IS_DMC) && \
    __DMC__ < 0x0844
# error stlsoft/containers/static_array.hpp is not compatible with Digital Mars C/C++ 8.43 or earlier
#elif defined(STLSOFT_COMPILER_IS_GCC) && \
      __GNUC__ < 3
# error stlsoft/containers/static_array.hpp is not compatible with GNU C/C++ prior to 3.0
#elif defined(STLSOFT_COMPILER_IS_MSVC) && \
    _MSC_VER < 1200
# error stlsoft/containers/static_array.hpp is not compatible with Visual C++ 5.0 or earlier
#endif /* compiler */

#ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_NULL_ALLOCATOR
# include <stlsoft/memory/null_allocator.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_NULL_ALLOCATOR */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
# include <stlsoft/util/std/iterator_helper.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER */
#ifndef STLSOFT_INCL_STLSOFT_CONTAINERS_UTIL_HPP_ARRAY_POLICIES
# include <stlsoft/containers/util/array_policies.hpp>  // for stlsoft::do_construction()
#endif /* !STLSOFT_INCL_STLSOFT_CONTAINERS_UTIL_HPP_ARRAY_POLICIES */
#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_COLLECTIONS_UTIL_HPP_COLLECTIONS
# include <stlsoft/collections/util/collections.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS */
#if defined(STLSOFT_COMPILER_IS_MSVC) && \
    defined(STLSOFT_CF_STD_LIBRARY_IS_STLPORT)
# include <string>                      // for std::string - sigh!
#endif /* compiler */
#include <stdexcept>                    // for std::out_of_range
#ifdef STLSOFT_UNITTEST
# include <algorithm>
# include <numeric>
#endif /* !STLSOFT_UNITTEST */

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

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

/* /////////////////////////////////////////////////////////////////////////
 * Forward declarations
 */

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

template<   ss_typename_param_k T
        ,   ss_size_t N0
        ,   ss_typename_param_k P
        ,   ss_typename_param_k M
        >
class static_array_1d;

template<   ss_typename_param_k T
        ,   ss_size_t N0
        ,   ss_size_t N1
        ,   ss_typename_param_k P
        ,   ss_typename_param_k M
        >
class static_array_2d;

template<   ss_typename_param_k T
        ,   ss_size_t N0
        ,   ss_size_t N1
        ,   ss_size_t N2
        ,   ss_typename_param_k P
        ,   ss_typename_param_k M
        >
class static_array_3d;

template<   ss_typename_param_k T
        ,   ss_size_t N0
        ,   ss_size_t N1
        ,   ss_size_t N2
        ,   ss_size_t N3
        ,   ss_typename_param_k P
        ,   ss_typename_param_k M
        >
class static_array_4d;

template<   ss_typename_param_k T
        ,   ss_size_t N0
        ,   ss_size_t N1
        ,   ss_size_t N2
        ,   ss_size_t N3
        ,   ss_size_t N4
        ,   ss_typename_param_k P
        ,   ss_typename_param_k M
        >
class static_array_5d;

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

////////////////////////////////////////////////////////////////////////////
// Classes

// class static_array_1d
/** \brief 1 dimensional static array
 *
 * \ingroup group__library__containers
 *
 * \param T The value type
 * \param N0 The first dimension extent
 * \param P The construction policy type
 */
template<   ss_typename_param_k T
        ,   ss_size_t N0
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
        ,   ss_typename_param_k P   =   do_construction<T>
        ,   ss_typename_param_k M   =   T[N0]
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
        ,   ss_typename_param_k P
        ,   ss_typename_param_k M
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
        >
class static_array_1d
    : public null_allocator<T>
    , public stl_collection_tag
{
public:
    typedef static_array_1d<T, N0, P, M>                    class_type;
    typedef T                                               dimension_type;
    typedef null_allocator<T>                               allocator_type;
    typedef P                                               policy_type;

    typedef T                                               value_type;
    typedef value_type                                      &reference;
    typedef value_type const                                &const_reference;
    typedef value_type                                      *pointer;
    typedef value_type const                                *const_pointer;
    typedef ss_size_t                                       size_type;
    typedef ss_size_t                                       index_type;
    typedef ss_ptrdiff_t                                    difference_type;

    typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
           ss_typename_type_k
#endif /* compiler */
                       pointer_iterator <   value_type
                                        ,   pointer
                                        ,   reference
                                        >::type             iterator;
    typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
         ss_typename_type_k
#endif /* compiler */
                       pointer_iterator <   value_type const
                                        ,   const_pointer
                                        ,   const_reference
                                        >::type             const_iterator;

#ifdef STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT
    typedef reverse_iterator_base       <   iterator
                                        ,   value_type
                                        ,   reference
                                        ,   pointer
                                        ,   difference_type
                                        >                   reverse_iterator;

    typedef const_reverse_iterator_base <   const_iterator
                                        ,   value_type const
                                        ,   const_reference
                                        ,   const_pointer
                                        ,   difference_type
                                        >                   const_reverse_iterator;
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */

// Construction
//protected:
    static_array_1d(T *data/* [N0] */);
public:
    static_array_1d();
    static_array_1d(value_type const& t);
    static_array_1d(class_type const& rhs);
    ~static_array_1d() stlsoft_throw_0();

// Access
public:
    reference               at(index_type i0);
    const_reference         at(index_type i0) const;

    reference               at_unchecked(index_type i0);
    const_reference         at_unchecked(index_type i0) const;

    reference               operator [](index_type i0);
    const_reference         operator [](index_type i0) const;

    reference               front();
    reference               back();
    const_reference         front() const;
    const_reference         back() const;

// State
public:
    static index_type       dimension0();
    static index_type       size();
    static ss_bool_t        empty();
    static size_type        max_size();

// Iteration
public:
    iterator                begin();
    iterator                end();
    const_iterator          begin() const;
    const_iterator          end() const;

#ifdef STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT
    reverse_iterator        rbegin();
    reverse_iterator        rend();
    const_reverse_iterator  rbegin() const;
    const_reverse_iterator  rend() const;
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */

// Access
public:

⌨️ 快捷键说明

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