mirror of
https://github.com/boostorg/array.git
synced 2025-06-25 20:11:45 +02:00
Compare commits
67 Commits
svn-branch
...
boost-1.65
Author | SHA1 | Date | |
---|---|---|---|
8f3aea2200 | |||
cef221d8b4 | |||
5d06f1074a | |||
4c27456a43 | |||
16824fe0f1 | |||
0d4fa276f4 | |||
cb4df41bd6 | |||
cd9888316a | |||
ce71078681 | |||
9678f6aa3b | |||
c0b1609ddb | |||
dfeb6bd0a5 | |||
1966dd034b | |||
40c5dae84c | |||
4584f63f01 | |||
2e0052d49f | |||
6ad6249e1c | |||
a73b6fb582 | |||
12fcbb59c2 | |||
4a60b8c146 | |||
117584a2ce | |||
97a26a1599 | |||
88abb34b4d | |||
e02e7dcc00 | |||
daeb19f693 | |||
ba1a2437cf | |||
f41b1d2d4c | |||
3db6930a22 | |||
859fb5aa97 | |||
f4a0cbd364 | |||
992299f2bf | |||
5a97de6f2e | |||
eea368fadf | |||
e6a44cf529 | |||
111e93aa4c | |||
5072c551ec | |||
26edbea113 | |||
97e912e82e | |||
05aa660128 | |||
9644ee6662 | |||
7256882760 | |||
5329bd6f1c | |||
80fa50df2e | |||
6fbc8ee741 | |||
38217688e1 | |||
a603bffc48 | |||
2595eda739 | |||
64e5394540 | |||
0c8902e8c2 | |||
88868ba0df | |||
99631823f6 | |||
5661b8cd63 | |||
86b069ad0e | |||
3d20bb1310 | |||
e7122b3f20 | |||
4dd2cf1b64 | |||
2e88dc228d | |||
0a4d7e81ef | |||
96d4c5f737 | |||
5a23b06a83 | |||
e85feee293 | |||
b6522b3f60 | |||
3044ab376c | |||
69188c998f | |||
4c5212f5e4 | |||
276cd991f3 | |||
1f8298fb08 |
19
doc/Jamfile.v2
Normal file
19
doc/Jamfile.v2
Normal file
@ -0,0 +1,19 @@
|
||||
#~ Copyright Marshall Clow 2013
|
||||
#~ 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)
|
||||
|
||||
using boostbook ;
|
||||
|
||||
boostbook standalone
|
||||
: array.xml
|
||||
: <xsl:param>boost.root=../../../.. ;
|
||||
|
||||
###############################################################################
|
||||
alias boostdoc
|
||||
: array.xml
|
||||
:
|
||||
:
|
||||
: ;
|
||||
explicit boostdoc ;
|
||||
alias boostrelease ;
|
||||
explicit boostrelease ;
|
@ -7,6 +7,10 @@
|
||||
<firstname>Nicolai</firstname>
|
||||
<surname>Josuttis</surname>
|
||||
</author>
|
||||
<maintainer>
|
||||
<firstname>Marshall</firstname>
|
||||
<surname>Clow</surname>
|
||||
</maintainer>
|
||||
|
||||
<copyright>
|
||||
<year>2001</year>
|
||||
@ -16,6 +20,11 @@
|
||||
<holder>Nicolai M. Josuttis</holder>
|
||||
</copyright>
|
||||
|
||||
<copyright>
|
||||
<year>2012</year>
|
||||
<holder>Marshall Clow</holder>
|
||||
</copyright>
|
||||
|
||||
<legalnotice>
|
||||
<para>Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at
|
||||
@ -68,7 +77,12 @@
|
||||
|
||||
<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>
|
||||
<ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm">http://www.open-std.org/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
|
||||
@ -171,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">
|
||||
@ -195,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">
|
||||
@ -460,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>
|
||||
|
@ -13,6 +13,9 @@
|
||||
* 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)
|
||||
@ -40,6 +43,7 @@
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/swap.hpp>
|
||||
|
||||
// Handles broken standard libraries better than <iterator>
|
||||
@ -71,19 +75,16 @@ namespace boost {
|
||||
// iterator support
|
||||
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)
|
||||
#if !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;
|
||||
@ -99,27 +100,32 @@ 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)
|
||||
{
|
||||
BOOST_ASSERT( i < N && "out of range" );
|
||||
return elems[i];
|
||||
return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i];
|
||||
}
|
||||
|
||||
const_reference operator[](size_type i) const
|
||||
/*BOOST_CONSTEXPR*/ const_reference operator[](size_type i) const
|
||||
{
|
||||
BOOST_ASSERT( i < N && "out of range" );
|
||||
return elems[i];
|
||||
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()
|
||||
@ -127,7 +133,7 @@ namespace boost {
|
||||
return elems[0];
|
||||
}
|
||||
|
||||
const_reference front() const
|
||||
BOOST_CONSTEXPR const_reference front() const
|
||||
{
|
||||
return elems[0];
|
||||
}
|
||||
@ -137,15 +143,15 @@ namespace boost {
|
||||
return elems[N-1];
|
||||
}
|
||||
|
||||
const_reference back() const
|
||||
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)
|
||||
@ -176,16 +182,12 @@ namespace boost {
|
||||
}
|
||||
|
||||
// check range (may be private because it is static)
|
||||
static void rangecheck (size_type i) {
|
||||
if (i >= size()) {
|
||||
std::out_of_range e("array<>: index out of range");
|
||||
boost::throw_exception(e);
|
||||
}
|
||||
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 > {
|
||||
|
||||
@ -202,19 +204,16 @@ namespace boost {
|
||||
// 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)
|
||||
#if !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;
|
||||
@ -230,10 +229,17 @@ 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*/)
|
||||
@ -241,14 +247,14 @@ namespace boost {
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
const_reference operator[](size_type /*i*/) const
|
||||
/*BOOST_CONSTEXPR*/ 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(); }
|
||||
/*BOOST_CONSTEXPR*/ const_reference at(size_type /*i*/) const { return failed_rangecheck(); }
|
||||
|
||||
// front() and back()
|
||||
reference front()
|
||||
@ -256,7 +262,7 @@ namespace boost {
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
const_reference front() const
|
||||
BOOST_CONSTEXPR const_reference front() const
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
@ -266,15 +272,15 @@ namespace boost {
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
const_reference back() const
|
||||
BOOST_CONSTEXPR 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; }
|
||||
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*/) {
|
||||
@ -301,7 +307,7 @@ namespace boost {
|
||||
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)
|
||||
#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
|
||||
@ -312,7 +318,6 @@ namespace boost {
|
||||
#endif
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
// comparisons
|
||||
template<class T, std::size_t N>
|
||||
@ -346,8 +351,104 @@ 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 detail::c_array<T,N>::type const& 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 It> std::size_t hash_range(It, It);
|
||||
|
||||
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)
|
||||
|
17
meta/libraries.json
Normal file
17
meta/libraries.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"key": "array",
|
||||
"name": "Array",
|
||||
"authors": [
|
||||
"Nicolai Josuttis"
|
||||
],
|
||||
"description": "STL compliant container wrapper for arrays of constant size.",
|
||||
"std": [
|
||||
"tr1"
|
||||
],
|
||||
"category": [
|
||||
"Containers"
|
||||
],
|
||||
"maintainers": [
|
||||
"Marshall Clow <marshall -at- idio.com>"
|
||||
]
|
||||
}
|
@ -4,11 +4,22 @@
|
||||
|
||||
import testing ;
|
||||
|
||||
alias unit_test_framework
|
||||
: # sources
|
||||
/boost//unit_test_framework
|
||||
;
|
||||
|
||||
test-suite array :
|
||||
[ run array0.cpp ]
|
||||
[ 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 ]
|
||||
;
|
||||
|
@ -9,18 +9,15 @@
|
||||
#include <iostream>
|
||||
#include <boost/array.hpp>
|
||||
|
||||
namespace {
|
||||
unsigned int failed_tests = 0;
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
void fail_test( const char * reason ) {
|
||||
++failed_tests;
|
||||
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
|
||||
}
|
||||
namespace {
|
||||
|
||||
template< class T >
|
||||
void BadValue( const T & )
|
||||
{
|
||||
fail_test( "Unexpected value" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
template< class T >
|
||||
@ -36,55 +33,41 @@ void RunTests()
|
||||
|
||||
// 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() );
|
||||
}
|
||||
BOOST_CHECK ( test_case.empty());
|
||||
BOOST_CHECK ( const_test_case.empty());
|
||||
|
||||
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 ] );
|
||||
}
|
||||
BOOST_CHECK ( test_case.size() == 0 );
|
||||
BOOST_CHECK ( const_test_case.size() == 0 );
|
||||
|
||||
// Assert requirements of TR1 6.2.2.4
|
||||
if( test_case.begin() != test_case.end() ) {
|
||||
fail_test( "Not an empty range" );
|
||||
}
|
||||
if( const_test_case.begin() != const_test_case.end() ) {
|
||||
fail_test( "Not an empty range" );
|
||||
}
|
||||
|
||||
if( test_case.begin() == const_test_case.begin() ) {
|
||||
fail_test( "iterators for different containers are not distinct" );
|
||||
}
|
||||
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 assigment operator and overloads are well formed
|
||||
// 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 ) );
|
||||
BadValue( test_case.at( 0 ));
|
||||
} catch ( const std::out_of_range & ) {
|
||||
}
|
||||
|
||||
@ -96,12 +79,11 @@ void RunTests()
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
RunTests< bool >();
|
||||
RunTests< void * >();
|
||||
RunTests< long double >();
|
||||
RunTests< std::string >();
|
||||
return failed_tests;
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,11 @@
|
||||
#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);
|
||||
|
||||
|
@ -39,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
|
||||
|
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
|
||||
}
|
||||
|
42
test/array_constexpr.cpp
Normal file
42
test/array_constexpr.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/* 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
|
49
test/array_getfail1.cpp
Normal file
49
test/array_getfail1.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/* 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 >();
|
||||
}
|
||||
|
Reference in New Issue
Block a user