Compare commits

..

2 Commits

Author SHA1 Message Date
bd59bafac6 This commit was manufactured by cvs2svn to create tag
'Version_1_31_0'.

[SVN r22162]
2004-02-04 15:24:32 +00:00
3eaf8bd9c5 This commit was manufactured by cvs2svn to create branch 'RC_1_31_0'.
[SVN r21427]
2003-12-30 12:10:04 +00:00
12 changed files with 106 additions and 557 deletions

View File

@ -1,9 +1,10 @@
/* simple example for using class array<> /* simple example for using class array<>
* *
* (C) Copyright Nicolai M. Josuttis 2001. * (C) Copyright Nicolai M. Josuttis 2001.
* Distributed under the Boost Software License, Version 1.0. (See * Permission to copy, use, modify, sell and distribute this software
* accompanying file LICENSE_1_0.txt or copy at * is granted provided this copyright notice appears in all copies.
* http://www.boost.org/LICENSE_1_0.txt) * This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
* *
* Changelog: * Changelog:
* 20 Jan 2001 - Removed boolalpha use since stock GCC doesn't support it * 20 Jan 2001 - Removed boolalpha use since stock GCC doesn't support it

View File

@ -1,15 +1,11 @@
/* example for using class array<> /* example for using class array<>
* (C) Copyright Nicolai M. Josuttis 2001. * (C) Copyright Nicolai M. Josuttis 2001.
* Distributed under the Boost Software License, Version 1.0. (See * Permission to copy, use, modify, sell and distribute this software
* accompanying file LICENSE_1_0.txt or copy at * is granted provided this copyright notice appears in all copies.
* http://www.boost.org/LICENSE_1_0.txt) * This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/ */
#ifndef _SCL_SECURE_NO_WARNINGS
// Suppress warnings from the std lib:
# define _SCL_SECURE_NO_WARNINGS
#endif
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <boost/array.hpp> #include <boost/array.hpp>

View File

@ -1,8 +1,9 @@
/* example for using class array<> /* example for using class array<>
* (C) Copyright Nicolai M. Josuttis 2001. * (C) Copyright Nicolai M. Josuttis 2001.
* Distributed under the Boost Software License, Version 1.0. (See * Permission to copy, use, modify, sell and distribute this software
* accompanying file LICENSE_1_0.txt or copy at * is granted provided this copyright notice appears in all copies.
* http://www.boost.org/LICENSE_1_0.txt) * This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/ */
#include <string> #include <string>
@ -21,7 +22,7 @@ int main()
// copy and change order // copy and change order
boost::array<std::string,4> seasons_orig = seasons; boost::array<std::string,4> seasons_orig = seasons;
for (std::size_t i=seasons.size()-1; i>0; --i) { for (unsigned i=seasons.size()-1; i>0; --i) {
std::swap(seasons.at(i),seasons.at((i+1)%seasons.size())); std::swap(seasons.at(i),seasons.at((i+1)%seasons.size()));
} }
@ -39,13 +40,6 @@ int main()
=seasons.rbegin(); pos<seasons.rend(); ++pos) { =seasons.rbegin(); pos<seasons.rend(); ++pos) {
std::cout << " " << *pos; std::cout << " " << *pos;
} }
// try constant reverse iterators
std::cout << "reverse: ";
for (boost::array<std::string,4>::const_reverse_iterator pos
=seasons.crbegin(); pos<seasons.crend(); ++pos) {
std::cout << " " << *pos;
}
std::cout << std::endl; std::cout << std::endl;
return 0; // makes Visual-C++ compiler happy return 0; // makes Visual-C++ compiler happy

View File

@ -1,8 +1,9 @@
/* example for using class array<> /* example for using class array<>
* (C) Copyright Nicolai M. Josuttis 2001. * (C) Copyright Nicolai M. Josuttis 2001.
* Distributed under the Boost Software License, Version 1.0. (See * Permission to copy, use, modify, sell and distribute this software
* accompanying file LICENSE_1_0.txt or copy at * is granted provided this copyright notice appears in all copies.
* http://www.boost.org/LICENSE_1_0.txt) * This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/ */
#include <algorithm> #include <algorithm>

View File

@ -1,8 +1,9 @@
/* simple example for using class array<> /* simple example for using class array<>
* (C) Copyright Nicolai M. Josuttis 2001. * (C) Copyright Nicolai M. Josuttis 2001.
* Distributed under the Boost Software License, Version 1.0. (See * Permission to copy, use, modify, sell and distribute this software
* accompanying file LICENSE_1_0.txt or copy at * is granted provided this copyright notice appears in all copies.
* http://www.boost.org/LICENSE_1_0.txt) * This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/ */
#include <iostream> #include <iostream>
@ -27,7 +28,7 @@ int main()
typedef boost::array<float,6> Array; typedef boost::array<float,6> Array;
// create and initialize an array // create and initialize an array
const Array a = { { 42.42f } }; const Array a = { { 42.42 } };
// use some common STL container operations // use some common STL container operations
std::cout << "static_size: " << a.size() << std::endl; std::cout << "static_size: " << a.size() << std::endl;

View File

@ -10,18 +10,15 @@
<copyright> <copyright>
<year>2001</year> <year>2001</year>
<year>2002</year>
<year>2003</year>
<year>2004</year>
<holder>Nicolai M. Josuttis</holder> <holder>Nicolai M. Josuttis</holder>
</copyright> </copyright>
<legalnotice> <legalnotice>
<para>Distributed under the Boost Software License, Version 1.0. <para>Permission to copy, use, modify, sell and distribute this
(See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at software is granted provided this copyright notice appears in
<ulink all copies. This software is provided "as is" without express or
url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>) implied warranty, and with no claim as to its suitability for
</para> any purpose.</para>
</legalnotice> </legalnotice>
<librarypurpose>STL compliant container wrapper for arrays of constant size</librarypurpose> <librarypurpose>STL compliant container wrapper for arrays of constant size</librarypurpose>
@ -66,13 +63,9 @@
<para>After considering different names, we decided to name this <para>After considering different names, we decided to name this
class simply <code><classname>array</classname></code>.</para> class simply <code><classname>array</classname></code>.</para>
<para>Note that this class is suggested to be part of the next <para>Class <code><classname>array</classname></code> fulfills
Technical Report, which will extend the C++ Standard (see most but not all of the requirements of "reversible containers"
<ulink url="http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm">http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm</ulink>).</para> (see Section 23.1, [lib.container.requirements] of the C++
<para>Class <code><classname>array</classname></code> fulfills most
but not all of the requirements of "reversible containers" (see
Section 23.1, [lib.container.requirements] of the C++
Standard). The reasons array is not an reversible STL container is Standard). The reasons array is not an reversible STL container is
because: because:
<itemizedlist spacing="compact"> <itemizedlist spacing="compact">
@ -283,12 +276,6 @@
<returns><simpara><code>elems</code></simpara></returns> <returns><simpara><code>elems</code></simpara></returns>
<throws><simpara>will not throw</simpara></throws> <throws><simpara>will not throw</simpara></throws>
</method> </method>
<method name="c_array">
<type>T*</type>
<returns><simpara><code>elems</code></simpara></returns>
<throws><simpara>will not throw</simpara></throws>
</method>
</method-group> </method-group>
<method-group name="modifiers"> <method-group name="modifiers">
@ -482,39 +469,51 @@
<simpara>Note that if there are fewer elements in the <simpara>Note that if there are fewer elements in the
initializer list, then each remaining element gets initializer list, then each remaining element gets
default-initialized (thus, it has a defined value).</simpara> default-initialized (thus, it has a defined value). However,
</listitem></itemizedlist></para> passing no initializer list means that the elements have an
indetermined initial value.</simpara></listitem>
<para>However, this approach has its drawbacks: <emphasis <listitem><simpara>It has no user-declared constructors.</simpara></listitem>
role="bold"> passing no initializer list means that the elements <listitem><simpara>It has no private or protected non-static data members.</simpara></listitem>
have an indetermined initial value</emphasis>, because the rule says <listitem><simpara>It has no base classes.</simpara></listitem>
that aggregates may have: <listitem><simpara>It has no virtual functions.</simpara></listitem>
<itemizedlist>
<listitem><simpara>No user-declared constructors.</simpara></listitem>
<listitem><simpara>No private or protected non-static data members.</simpara></listitem>
<listitem><simpara>No base classes.</simpara></listitem>
<listitem><simpara>No virtual functions.</simpara></listitem>
</itemizedlist> </itemizedlist>
</para> </para>
<para>The current implementation uses this approach. However, being
able to have indeterminate initial values is a big drawback. So,
please give me some feedback, how useful you consider this feature
to be.</para>
</section>
<para>Nevertheless, The current implementation uses this approach.</para> <section id="array.issues">
<title>Open Issues</title>
<para>Note that for standard conforming compilers it is possible to <itemizedlist>
use fewer braces (according to 8.5.1 (11) of the Standard). That is,
you can initialize an array as follows:</para>
<programlisting> <listitem>
<classname>boost::array</classname>&lt;int,4&gt; a = { 1, 2, 3 }; <simpara> Do we want initializer list support or would the
</programlisting> following be OK?:</simpara>
<para>I'd appreciate any constructive feedback. <emphasis <programlisting>int data[] = { 1, 2, 3, 4 }
role="bold">Please note: I don't have time to read all boost <classname>boost::array</classname>&lt;int,5&gt; x(data); // or <classname>boost::array</classname>&lt;int,data&gt; x;</programlisting>
mails. Thus, to make sure that feedback arrives to me, please send </listitem>
me a copy of each mail regarding this class.</emphasis></para>
<para>The code is provided "as is" without expressed or implied <listitem><simpara>Could "{ ... }" be used portably instead of "{
warranty.</para> { ... } }" to initialize values? 8.5.1 (11) of the Standard seems
to allow it; however, gcc 2.95.2 prints a warning
message.</simpara></listitem>
<listitem><simpara>Any way to have determinate initial values and
initializer list support?</simpara></listitem>
<listitem><simpara>Static_casts for reverse iterator stuff?</simpara></listitem>
</itemizedlist>
<para>I'd appreciate any constructive feedback. Please note: I don't
have time to read all boost mails. Thus, to make sure that <ulink
url="mailto:solutions@josuttis.com">feedback</ulink> arrives me,
please send me a copy of each mail regarding this class.</para>
</section> </section>
<section id="array.more.info"> <section id="array.more.info">

View File

@ -2,56 +2,36 @@
* an STL container (as wrapper) for arrays of constant size. * an STL container (as wrapper) for arrays of constant size.
* *
* See * See
* http://www.boost.org/libs/array/ * http://www.josuttis.com/cppcode
* for documentation. * for details and the latest version.
*
* The original author site is at: http://www.josuttis.com/
* *
* (C) Copyright Nicolai M. Josuttis 2001. * (C) Copyright Nicolai M. Josuttis 2001.
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
* *
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* 28 Dec 2010 - (mtc) Added cbegin and cend (and crbegin and crend) for C++Ox compatibility.
* 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group.
* See <http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#776> or Trac issue #3168
* Eventually, we should remove "assign" which is now a synonym for "fill" (Marshall Clow)
* 10 Mar 2010 - added workaround for SUNCC and !STLPort [trac #3893] (Marshall Clow)
* 29 Jan 2004 - c_array() added, BOOST_NO_PRIVATE_IN_AGGREGATE removed (Nico Josuttis)
* 23 Aug 2002 - fix for Non-MSVC compilers combined with MSVC libraries. * 23 Aug 2002 - fix for Non-MSVC compilers combined with MSVC libraries.
* 05 Aug 2001 - minor update (Nico Josuttis) * 05 Aug 2001 - minor update (Nico Josuttis)
* 20 Jan 2001 - STLport fix (Beman Dawes) * 20 Jan 2001 - STLport fix (Beman Dawes)
* 29 Sep 2000 - Initial Revision (Nico Josuttis) * 29 Sep 2000 - Initial Revision (Nico Josuttis)
*
* Jan 29, 2004
*/ */
// See http://www.boost.org/libs/array for Documentation.
#ifndef BOOST_ARRAY_HPP #ifndef BOOST_ARRAY_HPP
#define BOOST_ARRAY_HPP #define BOOST_ARRAY_HPP
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning(push)
# pragma warning(disable:4996) // 'std::equal': Function call with parameters that may be unsafe
# pragma warning(disable:4510) // boost::array<T,N>' : default constructor could not be generated
# pragma warning(disable:4610) // warning C4610: class 'boost::array<T,N>' can never be instantiated - user defined constructor required
#endif
#include <cstddef> #include <cstddef>
#include <stdexcept> #include <stdexcept>
#include <boost/assert.hpp>
#include <boost/swap.hpp>
// Handles broken standard libraries better than <iterator> // Handles broken standard libraries better than <iterator>
#include <boost/detail/iterator.hpp> #include <boost/detail/iterator.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm> #include <algorithm>
// FIXES for broken compilers // FIXES for broken compilers
#include <boost/config.hpp> #include <boost/config.hpp>
namespace boost { namespace boost {
template<class T, std::size_t N> template<class T, std::size_t N>
@ -72,11 +52,8 @@ namespace boost {
// iterator support // iterator support
iterator begin() { return elems; } iterator begin() { return elems; }
const_iterator begin() const { return elems; } const_iterator begin() const { return elems; }
const_iterator cbegin() const { return elems; }
iterator end() { return elems+N; } iterator end() { return elems+N; }
const_iterator end() const { return elems+N; } const_iterator end() const { return elems+N; }
const_iterator cend() const { return elems+N; }
// reverse iterator support // reverse iterator support
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS) #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
@ -88,11 +65,6 @@ namespace boost {
reference, iterator, reference> > reverse_iterator; reference, iterator, reference> > reverse_iterator;
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator, typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator,
const_reference, iterator, reference> > const_reverse_iterator; const_reference, iterator, reference> > const_reverse_iterator;
#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
value_type, reference, iterator, difference_type> reverse_iterator;
typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
value_type, const_reference, const_iterator, difference_type> const_reverse_iterator;
#else #else
// workaround for broken reverse_iterator implementations // workaround for broken reverse_iterator implementations
typedef std::reverse_iterator<iterator,T> reverse_iterator; typedef std::reverse_iterator<iterator,T> reverse_iterator;
@ -103,55 +75,24 @@ namespace boost {
const_reverse_iterator rbegin() const { const_reverse_iterator rbegin() const {
return const_reverse_iterator(end()); return const_reverse_iterator(end());
} }
const_reverse_iterator crbegin() const {
return const_reverse_iterator(end());
}
reverse_iterator rend() { return reverse_iterator(begin()); } reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const { const_reverse_iterator rend() const {
return const_reverse_iterator(begin()); return const_reverse_iterator(begin());
} }
const_reverse_iterator crend() const {
return const_reverse_iterator(begin());
}
// operator[] // operator[]
reference operator[](size_type i) reference operator[](size_type i) { return elems[i]; }
{ const_reference operator[](size_type i) const { return elems[i]; }
BOOST_ASSERT( i < N && "out of range" );
return elems[i];
}
const_reference operator[](size_type i) const
{
BOOST_ASSERT( i < N && "out of range" );
return elems[i];
}
// at() with range check // at() with range check
reference at(size_type i) { rangecheck(i); return elems[i]; } reference at(size_type i) { rangecheck(i); return elems[i]; }
const_reference at(size_type i) const { rangecheck(i); return elems[i]; } const_reference at(size_type i) const { rangecheck(i); return elems[i]; }
// front() and back() // front() and back()
reference front() reference front() { return elems[0]; }
{ const_reference front() const { return elems[0]; }
return elems[0]; reference back() { return elems[N-1]; }
} const_reference back() const { return elems[N-1]; }
const_reference front() const
{
return elems[0];
}
reference back()
{
return elems[N-1];
}
const_reference back() const
{
return elems[N-1];
}
// size is constant // size is constant
static size_type size() { return N; } static size_type size() { return N; }
@ -161,16 +102,11 @@ namespace boost {
// swap (note: linear complexity) // swap (note: linear complexity)
void swap (array<T,N>& y) { void swap (array<T,N>& y) {
for (size_type i = 0; i < N; ++i) std::swap_ranges(begin(),end(),y.begin());
boost::swap(elems[i],y.elems[i]);
} }
// direct access to data (read-only) // direct access to data
const T* data() const { return elems; } const T* data() const { return elems; }
T* data() { return elems; }
// use array as C array (direct read/write access to data)
T* c_array() { return elems; }
// assignment with type conversion // assignment with type conversion
template <typename T2> template <typename T2>
@ -180,161 +116,21 @@ namespace boost {
} }
// assign one value to all elements // assign one value to all elements
void assign (const T& value) { fill ( value ); } // A synonym for fill void assign (const T& value)
void fill (const T& value)
{ {
std::fill_n(begin(),size(),value); std::fill_n(begin(),size(),value);
} }
#ifndef BOOST_NO_PRIVATE_IN_AGGREGATE
private:
#endif
// check range (may be private because it is static) // check range (may be private because it is static)
static void rangecheck (size_type i) { static void rangecheck (size_type i) {
if (i >= size()) { if (i >= size()) { throw std::range_error("array"); }
std::out_of_range e("array<>: index out of range");
boost::throw_exception(e);
}
} }
}; };
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template< class T >
class array< T, 0 > {
public:
// type definitions
typedef T value_type;
typedef T* iterator;
typedef const T* const_iterator;
typedef T& reference;
typedef const T& const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
// iterator support
iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); }
const_iterator begin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
const_iterator cbegin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
iterator end() { return begin(); }
const_iterator end() const { return begin(); }
const_iterator cend() const { return cbegin(); }
// reverse iterator support
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
#elif defined(_MSC_VER) && (_MSC_VER == 1300) && defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB == 310)
// workaround for broken reverse_iterator in VC7
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, iterator,
reference, iterator, reference> > reverse_iterator;
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator,
const_reference, iterator, reference> > const_reverse_iterator;
#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
value_type, reference, iterator, difference_type> reverse_iterator;
typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
value_type, const_reference, const_iterator, difference_type> const_reverse_iterator;
#else
// workaround for broken reverse_iterator implementations
typedef std::reverse_iterator<iterator,T> reverse_iterator;
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
#endif
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
}
const_reverse_iterator crbegin() const {
return const_reverse_iterator(end());
}
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const {
return const_reverse_iterator(begin());
}
const_reverse_iterator crend() const {
return const_reverse_iterator(begin());
}
// operator[]
reference operator[](size_type /*i*/)
{
return failed_rangecheck();
}
const_reference operator[](size_type /*i*/) const
{
return failed_rangecheck();
}
// at() with range check
reference at(size_type /*i*/) { return failed_rangecheck(); }
const_reference at(size_type /*i*/) const { return failed_rangecheck(); }
// front() and back()
reference front()
{
return failed_rangecheck();
}
const_reference front() const
{
return failed_rangecheck();
}
reference back()
{
return failed_rangecheck();
}
const_reference back() const
{
return failed_rangecheck();
}
// size is constant
static size_type size() { return 0; }
static bool empty() { return true; }
static size_type max_size() { return 0; }
enum { static_size = 0 };
void swap (array<T,0>& /*y*/) {
}
// direct access to data (read-only)
const T* data() const { return 0; }
T* data() { return 0; }
// use array as C array (direct read/write access to data)
T* c_array() { return 0; }
// assignment with type conversion
template <typename T2>
array<T,0>& operator= (const array<T2,0>& ) {
return *this;
}
// assign one value to all elements
void assign (const T& value) { fill ( value ); }
void fill (const T& ) {}
// check range (may be private because it is static)
static reference failed_rangecheck () {
std::out_of_range e("attempt to access element of an empty array");
boost::throw_exception(e);
#if defined(BOOST_NO_EXCEPTIONS) || (!defined(BOOST_MSVC) && !defined(__PATHSCALE__))
//
// We need to return something here to keep
// some compilers happy: however we will never
// actually get here....
//
static T placeholder;
return placeholder;
#endif
}
};
#endif
// comparisons // comparisons
template<class T, std::size_t N> template<class T, std::size_t N>
bool operator== (const array<T,N>& x, const array<T,N>& y) { bool operator== (const array<T,N>& x, const array<T,N>& y) {
@ -367,71 +163,13 @@ namespace boost {
x.swap(y); x.swap(y);
} }
#if defined(__SUNPRO_CC)
// Trac ticket #4757; the Sun Solaris compiler can't handle
// syntax like 'T(&get_c_array(boost::array<T,N>& arg))[N]'
//
// We can't just use this for all compilers, because the
// borland compilers can't handle this form.
namespace detail {
template <typename T, std::size_t N> struct c_array
{
typedef T type[N];
};
}
// Specific for boost::array: simply returns its elems data member.
template <typename T, std::size_t N>
typename detail::c_array<T,N>::type& get_c_array(boost::array<T,N>& arg)
{
return arg.elems;
}
// Specific for boost::array: simply returns its elems data member.
template <typename T, std::size_t N>
typename const detail::c_array<T,N>::type& get_c_array(const boost::array<T,N>& arg)
{
return arg.elems;
}
#else
// Specific for boost::array: simply returns its elems data member.
template <typename T, std::size_t N>
T(&get_c_array(boost::array<T,N>& arg))[N]
{
return arg.elems;
}
// Const version.
template <typename T, std::size_t N>
const T(&get_c_array(const boost::array<T,N>& arg))[N]
{
return arg.elems;
}
#endif
#if 0
// Overload for std::array, assuming that std::array will have
// explicit conversion functions as discussed at the WG21 meeting
// in Summit, March 2009.
template <typename T, std::size_t N>
T(&get_c_array(std::array<T,N>& arg))[N]
{
return static_cast<T(&)[N]>(arg);
}
// Const version.
template <typename T, std::size_t N>
const T(&get_c_array(const std::array<T,N>& arg))[N]
{
return static_cast<T(&)[N]>(arg);
}
#endif
} /* namespace boost */ } /* namespace boost */
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning(pop)
#endif
#endif /*BOOST_ARRAY_HPP*/ #endif /*BOOST_ARRAY_HPP*/

View File

@ -4,10 +4,6 @@
</head> </head>
<body> <body>
Automatic redirection failed, please go to Automatic redirection failed, please go to
<a href="../../doc/html/array.html">../../doc/html/array.html</a> &nbsp;<hr> <a href="../../doc/html/array.html">../../doc/html/array.html</a>
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
</body> </body>
</html> </html>

View File

@ -3,9 +3,10 @@
* by Nicolai M. Josuttis, Addison-Wesley, 1999 * by Nicolai M. Josuttis, Addison-Wesley, 1999
* *
* (C) Copyright Nicolai M. Josuttis 1999. * (C) Copyright Nicolai M. Josuttis 1999.
* Distributed under the Boost Software License, Version 1.0. (See * Permission to copy, use, modify, sell and distribute this software
* accompanying file LICENSE_1_0.txt or copy at * is granted provided this copyright notice appears in all copies.
* http://www.boost.org/LICENSE_1_0.txt) * This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/ */
#include <iostream> #include <iostream>

View File

@ -1,15 +0,0 @@
#~ Copyright Rene Rivera 2008
#~ Distributed under the Boost Software License, Version 1.0.
#~ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
import testing ;
test-suite array :
[ run array0.cpp ]
[ run array1.cpp ]
[ run array2.cpp ]
[ run array3.cpp ]
[ run array4.cpp ]
[ run array5.cpp ]
[ run array6.cpp ]
;

View File

@ -1,115 +0,0 @@
/* tests for using class array<> specialization for size 0
* (C) Copyright Alisdair Meredith 2006.
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#include <string>
#include <iostream>
#include <boost/array.hpp>
namespace {
unsigned int failed_tests = 0;
void fail_test( const char * reason ) {
++failed_tests;
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
}
template< class T >
void BadValue( const T & )
{
fail_test( "Unexpected value" );
}
template< class T >
void RunTests()
{
typedef boost::array< T, 0 > test_type;
// Test value and aggegrate initialization
test_type test_case = {};
const boost::array< T, 0 > const_test_case = test_type();
test_case.fill ( T() );
// front/back and operator[] must compile, but calling them is undefined
// Likewise, all tests below should evaluate to false, avoiding undefined behaviour
if( !test_case.empty() ) {
BadValue( test_case.front() );
}
if( !const_test_case.empty() ) {
BadValue( const_test_case.back() );
}
if( test_case.size() > 0 ) {
BadValue( test_case[ 0 ] );
}
if( const_test_case.max_size() > 0 ) {
BadValue( const_test_case[ 0 ] );
}
// Assert requirements of TR1 6.2.2.4
if( test_case.begin() != test_case.end() ) {
fail_test( "Not an empty range" );
}
if( test_case.cbegin() != test_case.cend() ) {
fail_test( "Not an empty range" );
}
if( const_test_case.begin() != const_test_case.end() ) {
fail_test( "Not an empty range" );
}
if( const_test_case.cbegin() != const_test_case.cend() ) {
fail_test( "Not an empty range" );
}
if( test_case.begin() == const_test_case.begin() ) {
fail_test( "iterators for different containers are not distinct" );
}
if( test_case.data() == const_test_case.data() ) {
// Value of data is unspecified in TR1, so no requirement this test pass or fail
// However, it must compile!
}
// Check can safely use all iterator types with std algorithms
std::for_each( test_case.begin(), test_case.end(), BadValue< T > );
std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > );
std::for_each( test_case.cbegin(), test_case.cend(), BadValue< T > );
std::for_each( const_test_case.begin(), const_test_case.end(), BadValue< T > );
std::for_each( const_test_case.rbegin(), const_test_case.rend(), BadValue< T > );
std::for_each( const_test_case.cbegin(), const_test_case.cend(), BadValue< T > );
// Check swap is well formed
std::swap( test_case, test_case );
// Check assigment operator and overloads are well formed
test_case = const_test_case;
// Confirm at() throws the std lib defined exception
try {
BadValue( test_case.at( 0 ) );
} catch ( const std::out_of_range & ) {
}
try {
BadValue( const_test_case.at( 0 ) );
} catch ( const std::out_of_range & ) {
}
}
}
int main()
{
RunTests< bool >();
RunTests< void * >();
RunTests< long double >();
RunTests< std::string >();
return failed_tests;
}

View File

@ -1,48 +0,0 @@
/* tests for using class array<> specialization for size 0
* (C) Copyright Alisdair Meredith 2006.
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#include <string>
#include <iostream>
#include <boost/array.hpp>
#include <algorithm>
namespace {
unsigned int failed_tests = 0;
void fail_test( const char * reason ) {
++failed_tests;
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
}
template< class T >
void RunTests()
{
typedef boost::array< T, 5 > test_type;
typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 };
arr &aRef = get_c_array ( test_case );
if ( &*test_case.begin () != &aRef[0] )
fail_test ( "Array6: Same thing not equal?(1)" );
const arr &caRef = get_c_array ( test_case );
typename test_type::const_iterator iter = test_case.begin ();
if ( &*iter != &caRef[0] )
fail_test ( "Array6: Same thing not equal?(2)" );
}
}
int main()
{
RunTests< bool >();
RunTests< void * >();
RunTests< long double >();
RunTests< std::string >();
return failed_tests;
}