mirror of
https://github.com/boostorg/array.git
synced 2025-06-25 12:01:34 +02:00
Compare commits
52 Commits
boost-1.31
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
ed7eb32612 | |||
12fcbb59c2 | |||
4a60b8c146 | |||
117584a2ce | |||
97a26a1599 | |||
88abb34b4d | |||
e02e7dcc00 | |||
daeb19f693 | |||
f41b1d2d4c | |||
f4a0cbd364 | |||
992299f2bf | |||
e6a44cf529 | |||
111e93aa4c | |||
5072c551ec | |||
97e912e82e | |||
05aa660128 | |||
7256882760 | |||
5329bd6f1c | |||
80fa50df2e | |||
6fbc8ee741 | |||
38217688e1 | |||
2595eda739 | |||
64e5394540 | |||
c37498364e | |||
5e81100035 | |||
79cadb97d7 | |||
9609395af0 | |||
fb72e72640 | |||
e875287d55 | |||
100b5d687b | |||
7fb9412ea8 | |||
471bc9bf06 | |||
9cf5e0c9a1 | |||
d2910e195a | |||
b3ace9fb6e | |||
a6b531b5b1 | |||
9804292dad | |||
069b5e2ca1 | |||
526953fc5e | |||
b06f12b0b7 | |||
f0bbb8b211 | |||
d7a5408143 | |||
564e4029d0 | |||
0dc11c2f23 | |||
7da1c4b310 | |||
8f10fdf27e | |||
b41f7fdebe | |||
2fde5e334b | |||
4ee6e051fe | |||
bac6446111 | |||
cfb6d6eae6 | |||
0543286830 |
5
doc/Jamfile.v2
Normal file
5
doc/Jamfile.v2
Normal file
@ -0,0 +1,5 @@
|
||||
using boostbook ;
|
||||
|
||||
boostbook standalone
|
||||
: array.xml
|
||||
: <xsl:param>boost.root=../../../.. ;
|
182
doc/array.xml
182
doc/array.xml
@ -7,18 +7,30 @@
|
||||
<firstname>Nicolai</firstname>
|
||||
<surname>Josuttis</surname>
|
||||
</author>
|
||||
<maintainer>
|
||||
<firstname>Marshall</firstname>
|
||||
<surname>Clow</surname>
|
||||
</maintainer>
|
||||
|
||||
<copyright>
|
||||
<year>2001</year>
|
||||
<year>2002</year>
|
||||
<year>2003</year>
|
||||
<year>2004</year>
|
||||
<holder>Nicolai M. Josuttis</holder>
|
||||
</copyright>
|
||||
|
||||
<copyright>
|
||||
<year>2012</year>
|
||||
<holder>Marshall Clow</holder>
|
||||
</copyright>
|
||||
|
||||
<legalnotice>
|
||||
<para>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.</para>
|
||||
<para>Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at
|
||||
<ulink
|
||||
url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>)
|
||||
</para>
|
||||
</legalnotice>
|
||||
|
||||
<librarypurpose>STL compliant container wrapper for arrays of constant size</librarypurpose>
|
||||
@ -63,9 +75,18 @@
|
||||
<para>After considering different names, we decided to name this
|
||||
class simply <code><classname>array</classname></code>.</para>
|
||||
|
||||
<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++
|
||||
<para>Note that this class is suggested to be part of the next
|
||||
Technical Report, which will extend the C++ Standard (see
|
||||
<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>
|
||||
|
||||
<para>Update: <code>std::array</code> is (as of C++11) part of the C++ standard.
|
||||
The differences between <code>boost::array</code> and <code>std::array</code> are minimal.
|
||||
If you are using C++11, you should consider using <code>std::array</code> instead of <code>boost::array</code>.
|
||||
</para>
|
||||
|
||||
<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
|
||||
because:
|
||||
<itemizedlist spacing="compact">
|
||||
@ -164,6 +185,24 @@
|
||||
<returns><simpara>iterator for position after the last element</simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</overloaded-method>
|
||||
|
||||
<overloaded-method name="cbegin" cv="const">
|
||||
<signature>
|
||||
<type>const_iterator</type>
|
||||
</signature>
|
||||
|
||||
<returns><simpara>constant iterator for the first element</simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</overloaded-method>
|
||||
|
||||
<overloaded-method name="cend" cv="const">
|
||||
<signature>
|
||||
<type>const_iterator</type>
|
||||
</signature>
|
||||
|
||||
<returns><simpara>constant iterator for position after the last element</simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</overloaded-method>
|
||||
</method-group>
|
||||
|
||||
<method-group name="reverse iterator support">
|
||||
@ -188,6 +227,24 @@
|
||||
|
||||
<returns><simpara>reverse iterator for position after the last element in reverse iteration</simpara></returns>
|
||||
</overloaded-method>
|
||||
|
||||
<overloaded-method name="crbegin" cv="const">
|
||||
<signature>
|
||||
<type>const_reverse_iterator</type>
|
||||
</signature>
|
||||
|
||||
<returns><simpara>constant reverse iterator for the first element of reverse iteration</simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</overloaded-method>
|
||||
|
||||
<overloaded-method name="crend" cv="const">
|
||||
<signature>
|
||||
<type>const_reverse_iterator</type>
|
||||
</signature>
|
||||
|
||||
<returns><simpara>constant reverse iterator for position after the last element in reverse iteration</simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</overloaded-method>
|
||||
</method-group>
|
||||
|
||||
<method-group name="capacity">
|
||||
@ -276,6 +333,12 @@
|
||||
<returns><simpara><code>elems</code></simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</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 name="modifiers">
|
||||
@ -447,6 +510,49 @@
|
||||
<returns><simpara><code>!(x < y)</code></simpara></returns>
|
||||
</function>
|
||||
</free-function-group>
|
||||
|
||||
<free-function-group name="specializations">
|
||||
<function name="boost::get">
|
||||
<template>
|
||||
<template-type-parameter name="T"/>
|
||||
<template-nontype-parameter name="N">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
<template-nontype-parameter name="Idx">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
</template>
|
||||
|
||||
<type>T</type>
|
||||
|
||||
<parameter name="arr">
|
||||
<paramtype><classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
<returns><simpara>element of array with index <code>Idx</code></simpara></returns>
|
||||
<effects><simpara>Will <code>static_assert</code> if <code>Idx >= N</code></simpara></effects>
|
||||
</function>
|
||||
|
||||
<function name="boost::get">
|
||||
<template>
|
||||
<template-type-parameter name="T"/>
|
||||
<template-nontype-parameter name="N">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
<template-nontype-parameter name="Idx">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
</template>
|
||||
|
||||
<type>T</type>
|
||||
|
||||
<parameter name="arr">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
<returns><simpara>const element of array with index <code>Idx</code></simpara></returns>
|
||||
<effects><simpara>Will <code>static_assert</code> if <code>Idx >= N</code></simpara></effects>
|
||||
</function>
|
||||
</free-function-group>
|
||||
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
@ -469,51 +575,39 @@
|
||||
|
||||
<simpara>Note that if there are fewer elements in the
|
||||
initializer list, then each remaining element gets
|
||||
default-initialized (thus, it has a defined value). However,
|
||||
passing no initializer list means that the elements have an
|
||||
indetermined initial value.</simpara></listitem>
|
||||
default-initialized (thus, it has a defined value).</simpara>
|
||||
</listitem></itemizedlist></para>
|
||||
|
||||
<listitem><simpara>It has no user-declared constructors.</simpara></listitem>
|
||||
<listitem><simpara>It has no private or protected non-static data members.</simpara></listitem>
|
||||
<listitem><simpara>It has no base classes.</simpara></listitem>
|
||||
<listitem><simpara>It has no virtual functions.</simpara></listitem>
|
||||
<para>However, this approach has its drawbacks: <emphasis
|
||||
role="bold"> passing no initializer list means that the elements
|
||||
have an indetermined initial value</emphasis>, because the rule says
|
||||
that aggregates may have:
|
||||
<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>
|
||||
|
||||
</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>
|
||||
|
||||
<section id="array.issues">
|
||||
<title>Open Issues</title>
|
||||
<para>Nevertheless, The current implementation uses this approach.</para>
|
||||
|
||||
<itemizedlist>
|
||||
<para>Note that for standard conforming compilers it is possible to
|
||||
use fewer braces (according to 8.5.1 (11) of the Standard). That is,
|
||||
you can initialize an array as follows:</para>
|
||||
|
||||
<listitem>
|
||||
<simpara> Do we want initializer list support or would the
|
||||
following be OK?:</simpara>
|
||||
<programlisting>
|
||||
<classname>boost::array</classname><int,4> a = { 1, 2, 3 };
|
||||
</programlisting>
|
||||
|
||||
<programlisting>int data[] = { 1, 2, 3, 4 }
|
||||
<classname>boost::array</classname><int,5> x(data); // or <classname>boost::array</classname><int,data> x;</programlisting>
|
||||
</listitem>
|
||||
<para>I'd appreciate any constructive feedback. <emphasis
|
||||
role="bold">Please note: I don't have time to read all boost
|
||||
mails. Thus, to make sure that feedback arrives to me, please send
|
||||
me a copy of each mail regarding this class.</emphasis></para>
|
||||
|
||||
<listitem><simpara>Could "{ ... }" be used portably instead of "{
|
||||
{ ... } }" 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>
|
||||
<para>The code is provided "as is" without expressed or implied
|
||||
warranty.</para>
|
||||
|
||||
<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 id="array.more.info">
|
||||
|
@ -2,36 +2,60 @@
|
||||
* an STL container (as wrapper) for arrays of constant size.
|
||||
*
|
||||
* See
|
||||
* http://www.josuttis.com/cppcode
|
||||
* for details and the latest version.
|
||||
* http://www.boost.org/libs/array/
|
||||
* for documentation.
|
||||
*
|
||||
* The original author site is at: http://www.josuttis.com/
|
||||
*
|
||||
* (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)
|
||||
*
|
||||
* 9 Jan 2013 - (mtc) Added constexpr
|
||||
* 14 Apr 2012 - (mtc) Added support for boost::hash
|
||||
* 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.
|
||||
* 05 Aug 2001 - minor update (Nico Josuttis)
|
||||
* 20 Jan 2001 - STLport fix (Beman Dawes)
|
||||
* 29 Sep 2000 - Initial Revision (Nico Josuttis)
|
||||
*
|
||||
* Jan 29, 2004
|
||||
*/
|
||||
|
||||
// See http://www.boost.org/libs/array for Documentation.
|
||||
|
||||
#ifndef 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 <stdexcept>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/swap.hpp>
|
||||
|
||||
// Handles broken standard libraries better than <iterator>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/functional/hash_fwd.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
// FIXES for broken compilers
|
||||
#include <boost/config.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T, std::size_t N>
|
||||
@ -48,12 +72,15 @@ namespace boost {
|
||||
typedef const T& const_reference;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
|
||||
// iterator support
|
||||
iterator begin() { return elems; }
|
||||
const_iterator begin() const { return elems; }
|
||||
iterator end() { return elems+N; }
|
||||
const_iterator end() const { return elems+N; }
|
||||
iterator begin() { return elems; }
|
||||
const_iterator begin() const { return elems; }
|
||||
const_iterator cbegin() const { return elems; }
|
||||
|
||||
iterator end() { return elems+N; }
|
||||
const_iterator end() const { return elems+N; }
|
||||
const_iterator cend() const { return elems+N; }
|
||||
|
||||
// reverse iterator support
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
||||
@ -65,6 +92,11 @@ namespace boost {
|
||||
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;
|
||||
@ -75,38 +107,72 @@ namespace boost {
|
||||
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 elems[i]; }
|
||||
const_reference operator[](size_type i) const { return elems[i]; }
|
||||
reference operator[](size_type i)
|
||||
{
|
||||
return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i];
|
||||
}
|
||||
|
||||
/*BOOST_CONSTEXPR*/ const_reference operator[](size_type i) const
|
||||
{
|
||||
return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i];
|
||||
}
|
||||
|
||||
// at() with range check
|
||||
reference at(size_type i) { rangecheck(i); return elems[i]; }
|
||||
const_reference at(size_type i) const { rangecheck(i); return elems[i]; }
|
||||
reference at(size_type i) { return rangecheck(i), elems[i]; }
|
||||
/*BOOST_CONSTEXPR*/ const_reference at(size_type i) const { return rangecheck(i), elems[i]; }
|
||||
|
||||
// front() and back()
|
||||
reference front() { return elems[0]; }
|
||||
const_reference front() const { return elems[0]; }
|
||||
reference back() { return elems[N-1]; }
|
||||
const_reference back() const { return elems[N-1]; }
|
||||
reference front()
|
||||
{
|
||||
return elems[0];
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR const_reference front() const
|
||||
{
|
||||
return elems[0];
|
||||
}
|
||||
|
||||
reference back()
|
||||
{
|
||||
return elems[N-1];
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR const_reference back() const
|
||||
{
|
||||
return elems[N-1];
|
||||
}
|
||||
|
||||
// size is constant
|
||||
static size_type size() { return N; }
|
||||
static bool empty() { return false; }
|
||||
static size_type max_size() { return N; }
|
||||
static BOOST_CONSTEXPR size_type size() { return N; }
|
||||
static BOOST_CONSTEXPR bool empty() { return false; }
|
||||
static BOOST_CONSTEXPR size_type max_size() { return N; }
|
||||
enum { static_size = N };
|
||||
|
||||
// swap (note: linear complexity)
|
||||
void swap (array<T,N>& y) {
|
||||
std::swap_ranges(begin(),end(),y.begin());
|
||||
for (size_type i = 0; i < N; ++i)
|
||||
boost::swap(elems[i],y.elems[i]);
|
||||
}
|
||||
|
||||
// direct access to data
|
||||
// direct access to data (read-only)
|
||||
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
|
||||
template <typename T2>
|
||||
@ -116,21 +182,158 @@ namespace boost {
|
||||
}
|
||||
|
||||
// assign one value to all elements
|
||||
void assign (const T& value)
|
||||
void assign (const T& value) { fill ( value ); } // A synonym for fill
|
||||
void fill (const T& value)
|
||||
{
|
||||
std::fill_n(begin(),size(),value);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_PRIVATE_IN_AGGREGATE
|
||||
private:
|
||||
#endif
|
||||
// check range (may be private because it is static)
|
||||
static void rangecheck (size_type i) {
|
||||
if (i >= size()) { throw std::range_error("array"); }
|
||||
static BOOST_CONSTEXPR bool rangecheck (size_type i) {
|
||||
return i > size() ? boost::throw_exception(std::out_of_range ("array<>: index out of range")), true : true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
/*BOOST_CONSTEXPR*/ const_reference operator[](size_type /*i*/) const
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
// at() with range check
|
||||
reference at(size_type /*i*/) { return failed_rangecheck(); }
|
||||
/*BOOST_CONSTEXPR*/ const_reference at(size_type /*i*/) const { return failed_rangecheck(); }
|
||||
|
||||
// front() and back()
|
||||
reference front()
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR const_reference front() const
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
reference back()
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR const_reference back() const
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
// size is constant
|
||||
static BOOST_CONSTEXPR size_type size() { return 0; }
|
||||
static BOOST_CONSTEXPR bool empty() { return true; }
|
||||
static BOOST_CONSTEXPR 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
|
||||
template<class T, std::size_t N>
|
||||
bool operator== (const array<T,N>& x, const array<T,N>& y) {
|
||||
@ -163,13 +366,106 @@ namespace boost {
|
||||
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
|
||||
|
||||
|
||||
template<class T, std::size_t N>
|
||||
std::size_t hash_value(const array<T,N>& arr)
|
||||
{
|
||||
return boost::hash_range(arr.begin(), arr.end());
|
||||
}
|
||||
|
||||
template <size_t Idx, typename T, size_t N>
|
||||
T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT {
|
||||
BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(boost::array &) index out of range" );
|
||||
return arr[Idx];
|
||||
}
|
||||
|
||||
template <size_t Idx, typename T, size_t N>
|
||||
const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT {
|
||||
BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(const boost::array &) index out of range" );
|
||||
return arr[Idx];
|
||||
}
|
||||
|
||||
} /* namespace boost */
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
// If we don't have std::array, I'm assuming that we don't have std::get
|
||||
namespace std {
|
||||
template <size_t Idx, typename T, size_t N>
|
||||
T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT {
|
||||
BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(boost::array &) index out of range" );
|
||||
return arr[Idx];
|
||||
}
|
||||
|
||||
template <size_t Idx, typename T, size_t N>
|
||||
const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT {
|
||||
BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(const boost::array &) index out of range" );
|
||||
return arr[Idx];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif /*BOOST_ARRAY_HPP*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -4,6 +4,10 @@
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="../../doc/html/array.html">../../doc/html/array.html</a>
|
||||
<a href="../../doc/html/array.html">../../doc/html/array.html</a> <hr>
|
||||
<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>
|
||||
</html>
|
||||
</html>
|
25
test/Jamfile.v2
Normal file
25
test/Jamfile.v2
Normal file
@ -0,0 +1,25 @@
|
||||
#~ 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 ;
|
||||
|
||||
alias unit_test_framework
|
||||
: # sources
|
||||
/boost//unit_test_framework
|
||||
;
|
||||
|
||||
test-suite array :
|
||||
[ run array0.cpp unit_test_framework : : : : array0 ]
|
||||
[ run array1.cpp ]
|
||||
[ run array2.cpp ]
|
||||
[ run array3.cpp ]
|
||||
[ run array4.cpp ]
|
||||
[ run array5.cpp ]
|
||||
[ run array6.cpp unit_test_framework : : : : array6 ]
|
||||
[ run array7.cpp unit_test_framework : : : : array7 ]
|
||||
# [ run array_constexpr.cpp unit_test_framework : : : : array_constexpr ]
|
||||
[ compile-fail array_getfail1.cpp ]
|
||||
[ compile-fail array_getfail2.cpp ]
|
||||
[ run array_hash.cpp unit_test_framework : : : : array_hash ]
|
||||
;
|
89
test/array0.cpp
Normal file
89
test/array0.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/* 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>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
template< class T >
|
||||
void BadValue( const T & )
|
||||
{
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
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
|
||||
BOOST_CHECK ( test_case.empty());
|
||||
BOOST_CHECK ( const_test_case.empty());
|
||||
|
||||
BOOST_CHECK ( test_case.size() == 0 );
|
||||
BOOST_CHECK ( const_test_case.size() == 0 );
|
||||
|
||||
// Assert requirements of TR1 6.2.2.4
|
||||
BOOST_CHECK ( test_case.begin() == test_case.end());
|
||||
BOOST_CHECK ( test_case.cbegin() == test_case.cend());
|
||||
BOOST_CHECK ( const_test_case.begin() == const_test_case.end());
|
||||
BOOST_CHECK ( const_test_case.cbegin() == const_test_case.cend());
|
||||
|
||||
BOOST_CHECK ( test_case.begin() != const_test_case.begin() );
|
||||
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 assignment 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 & ) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
RunTests< bool >();
|
||||
RunTests< void * >();
|
||||
RunTests< long double >();
|
||||
RunTests< std::string >();
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
/* simple example for using class array<>
|
||||
*
|
||||
* (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)
|
||||
*
|
||||
* Changelog:
|
||||
* 20 Jan 2001 - Removed boolalpha use since stock GCC doesn't support it
|
@ -1,22 +1,25 @@
|
||||
/* example for using class array<>
|
||||
* (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)
|
||||
*/
|
||||
|
||||
#ifndef _SCL_SECURE_NO_WARNINGS
|
||||
// Suppress warnings from the std lib:
|
||||
# define _SCL_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <boost/array.hpp>
|
||||
#include "print.hpp"
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create and initialize array
|
||||
array<int,10> a = { { 1, 2, 3, 4, 5 } };
|
||||
boost::array<int,10> a = { { 1, 2, 3, 4, 5 } };
|
||||
|
||||
print_elements(a);
|
||||
|
@ -1,9 +1,8 @@
|
||||
/* example for using class array<>
|
||||
* (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)
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
@ -22,7 +21,7 @@ int main()
|
||||
|
||||
// copy and change order
|
||||
boost::array<std::string,4> seasons_orig = seasons;
|
||||
for (unsigned i=seasons.size()-1; i>0; --i) {
|
||||
for (std::size_t i=seasons.size()-1; i>0; --i) {
|
||||
std::swap(seasons.at(i),seasons.at((i+1)%seasons.size()));
|
||||
}
|
||||
|
||||
@ -40,6 +39,13 @@ int main()
|
||||
=seasons.rbegin(); pos<seasons.rend(); ++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;
|
||||
|
||||
return 0; // makes Visual-C++ compiler happy
|
@ -1,9 +1,8 @@
|
||||
/* example for using class array<>
|
||||
* (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)
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
@ -1,9 +1,8 @@
|
||||
/* simple example for using class array<>
|
||||
* (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)
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
@ -28,7 +27,7 @@ int main()
|
||||
typedef boost::array<float,6> Array;
|
||||
|
||||
// create and initialize an array
|
||||
const Array a = { { 42.42 } };
|
||||
const Array a = { { 42.42f } };
|
||||
|
||||
// use some common STL container operations
|
||||
std::cout << "static_size: " << a.size() << std::endl;
|
40
test/array6.cpp
Normal file
40
test/array6.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/* 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>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace {
|
||||
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 );
|
||||
BOOST_CHECK ( &*test_case.begin () == &aRef[0] );
|
||||
|
||||
const arr &caRef = get_c_array ( test_case );
|
||||
typename test_type::const_iterator iter = test_case.begin ();
|
||||
BOOST_CHECK ( &*iter == &caRef[0] );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
RunTests< bool >();
|
||||
RunTests< void * >();
|
||||
RunTests< long double >();
|
||||
RunTests< std::string >();
|
||||
}
|
||||
|
67
test/array7.cpp
Normal file
67
test/array7.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/* tests using std::get on boost:array
|
||||
* (C) Copyright Marshall Clow 2012
|
||||
* 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>
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
#include <array>
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
template< class T >
|
||||
void RunStdTests()
|
||||
{
|
||||
typedef boost::array< T, 5 > test_type;
|
||||
typedef T arr[5];
|
||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
||||
|
||||
T &aRef = std::get<0> ( test_case );
|
||||
BOOST_CHECK ( &*test_case.begin () == &aRef );
|
||||
|
||||
const T &caRef = std::get<0> ( test_case );
|
||||
BOOST_CHECK ( &*test_case.cbegin () == &caRef );
|
||||
}
|
||||
#endif
|
||||
|
||||
template< class T >
|
||||
void RunBoostTests()
|
||||
{
|
||||
typedef boost::array< T, 5 > test_type;
|
||||
typedef T arr[5];
|
||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
||||
|
||||
T &aRef = boost::get<0> ( test_case );
|
||||
BOOST_CHECK ( &*test_case.begin () == &aRef );
|
||||
|
||||
const T &caRef = boost::get<0> ( test_case );
|
||||
BOOST_CHECK ( &*test_case.cbegin () == &caRef );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
RunBoostTests< bool >();
|
||||
RunBoostTests< void * >();
|
||||
RunBoostTests< long double >();
|
||||
RunBoostTests< std::string >();
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
RunStdTests< bool >();
|
||||
RunStdTests< void * >();
|
||||
RunStdTests< long double >();
|
||||
RunStdTests< std::string >();
|
||||
#endif
|
||||
}
|
||||
|
43
test/array_constexpr.cpp
Normal file
43
test/array_constexpr.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/* tests using constexpr on boost:array
|
||||
* (C) Copyright Marshall Clow 2012
|
||||
* 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>
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
#include <array>
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#ifndef BOOST_NO_CXX11_CONSTEXPR
|
||||
constexpr boost::array<int, 10> arr {{ 0,1,2,3,4,5,6,7,8,9 }};
|
||||
constexpr std::array<int, 10> arr_std {{ 0,1,2,3,4,5,6,7,8,9 }};
|
||||
|
||||
template <typename T>
|
||||
void sink ( T t ) {}
|
||||
|
||||
template <typename T, size_t N>
|
||||
void sink ( boost::array<T,N> &arr ) {}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
// constexpr int two = arr_std.at (2);
|
||||
constexpr int three = arr.at (3);
|
||||
int whatever [ arr.at(4) ];
|
||||
(void)three;
|
||||
(void) whatever;
|
||||
}
|
||||
|
||||
#else // no constexpr means no constexpr tests!
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
50
test/array_getfail1.cpp
Normal file
50
test/array_getfail1.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/* tests using std::get on boost:array
|
||||
* (C) Copyright Marshall Clow 2012
|
||||
* 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 <boost/array.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
#include <array>
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
template< class T >
|
||||
void RunStdTests()
|
||||
{
|
||||
typedef boost::array< T, 5 > test_type;
|
||||
typedef T arr[5];
|
||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
||||
|
||||
T &aRef = std::get<5> ( test_case ); // should fail to compile
|
||||
BOOST_CHECK ( &*test_case.begin () == &aRef );
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
RunStdTests< bool >();
|
||||
RunStdTests< void * >();
|
||||
RunStdTests< long double >();
|
||||
RunStdTests< std::string >();
|
||||
#else
|
||||
BOOST_STATIC_ASSERT ( false ); // fail on C++03 systems.
|
||||
#endif
|
||||
}
|
||||
|
64
test/array_getfail2.cpp
Normal file
64
test/array_getfail2.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/* tests using std::get on boost:array
|
||||
* (C) Copyright Marshall Clow 2012
|
||||
* 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>
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
#include <array>
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
template< class T >
|
||||
void RunStdTests()
|
||||
{
|
||||
typedef boost::array< T, 5 > test_type;
|
||||
typedef T arr[5];
|
||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
||||
|
||||
T &aRef = std::get<0> ( test_case );
|
||||
BOOST_CHECK ( &*test_case.begin () == &aRef );
|
||||
|
||||
const T &caRef = std::get<0> ( test_case );
|
||||
BOOST_CHECK ( &*test_case.cbegin () == &caRef );
|
||||
}
|
||||
#endif
|
||||
|
||||
template< class T >
|
||||
void RunBoostTests()
|
||||
{
|
||||
typedef boost::array< T, 5 > test_type;
|
||||
typedef T arr[5];
|
||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
||||
|
||||
T &aRef = boost::get<5> ( test_case );
|
||||
BOOST_CHECK ( &*test_case.begin () == &aRef );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
RunBoostTests< bool >();
|
||||
RunBoostTests< void * >();
|
||||
RunBoostTests< long double >();
|
||||
RunBoostTests< std::string >();
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
RunStdTests< bool >();
|
||||
RunStdTests< void * >();
|
||||
RunStdTests< long double >();
|
||||
RunStdTests< std::string >();
|
||||
#endif
|
||||
}
|
||||
|
43
test/array_hash.cpp
Normal file
43
test/array_hash.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/* tests for using boost::hash with boost::array
|
||||
* (C) Copyright Marshall Clow 2012
|
||||
* 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>
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
template< class T >
|
||||
void RunTests()
|
||||
{
|
||||
// std::size_t hash0 = boost::hash<boost::array<T,0> > () ( boost::array<T, 0> ());
|
||||
// std::size_t hash1 = boost::hash<boost::array<T,1> > () ( boost::array<T, 1> ());
|
||||
|
||||
typedef boost::array< T, 5 > barr;
|
||||
typedef T arr[5];
|
||||
barr test_barr = {{ 1, 1, 2, 3, 5 }};
|
||||
arr test_arr = { 1, 1, 2, 3, 5 };
|
||||
|
||||
std::size_t bhash = boost::hash<barr> () ( test_barr );
|
||||
std::size_t ahash = boost::hash<arr> () ( test_arr );
|
||||
BOOST_CHECK ( ahash == bhash );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
RunTests< int >();
|
||||
RunTests< long >();
|
||||
RunTests< long double >();
|
||||
}
|
||||
|
@ -3,10 +3,9 @@
|
||||
* by Nicolai M. Josuttis, Addison-Wesley, 1999
|
||||
*
|
||||
* (C) Copyright Nicolai M. Josuttis 1999.
|
||||
* 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)
|
||||
*/
|
||||
#include <iostream>
|
||||
|
Reference in New Issue
Block a user