mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-09 00:50:52 +08:00
tr1: New.
2004-10-07 Benjamin Kosnik <bkoz@redhat.com> * include/tr1: New. * include/tr1/array: New. * include/Makefile.am (tr1_headers): New. (stamp-tr1): New. (install-headers): New. (allstamped): Add stamp-tr1. * include/ext/array_allocator.h: New. * include/Makefile.am: Add. * include/Makefile.in: Regenerate. * testsuite/ext/array_allocator/1.cc: New. * testsuite/ext/array_allocator/2.cc: New. From-SVN: r88711
This commit is contained in:
parent
446e877825
commit
3febde356c
@ -1,3 +1,18 @@
|
||||
2004-10-07 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
* include/tr1: New.
|
||||
* include/tr1/array: New.
|
||||
* include/Makefile.am (tr1_headers): New.
|
||||
(stamp-tr1): New.
|
||||
(install-headers): New.
|
||||
(allstamped): Add stamp-tr1.
|
||||
|
||||
* include/ext/array_allocator.h: New.
|
||||
* include/Makefile.am: Add.
|
||||
* include/Makefile.in: Regenerate.
|
||||
* testsuite/ext/array_allocator/1.cc: New.
|
||||
* testsuite/ext/array_allocator/2.cc: New.
|
||||
|
||||
2004-10-07 Richard Earnshaw <rearnsha@arm.com>
|
||||
|
||||
* testsuite/lib/libstdc++.exp (libstdc++_exit): New proc.
|
||||
|
@ -201,6 +201,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext
|
||||
ext_builddir = ./ext
|
||||
ext_headers = \
|
||||
${ext_srcdir}/algorithm \
|
||||
${ext_srcdir}/array_allocator.h \
|
||||
${ext_srcdir}/bitmap_allocator.h \
|
||||
${ext_srcdir}/debug_allocator.h \
|
||||
${ext_srcdir}/enc_filebuf.h \
|
||||
@ -224,6 +225,11 @@ ext_headers = \
|
||||
${ext_srcdir}/hash_fun.h \
|
||||
${ext_srcdir}/hashtable.h
|
||||
|
||||
tr1_srcdir = ${glibcxx_srcdir}/include/tr1
|
||||
tr1_builddir = ./tr1
|
||||
tr1_headers = \
|
||||
${tr1_srcdir}/array
|
||||
|
||||
# This is the common subset of files that all three "C" header models use.
|
||||
c_base_srcdir = $(C_INCLUDE_DIR)
|
||||
c_base_builddir = .
|
||||
@ -380,7 +386,7 @@ endif
|
||||
# CLEANFILES and all-local are kept up-to-date.
|
||||
allstamped = \
|
||||
stamp-std stamp-bits stamp-c_base stamp-c_compatibility \
|
||||
stamp-backward stamp-ext stamp-debug stamp-host
|
||||
stamp-backward stamp-ext stamp-tr1 stamp-debug stamp-host
|
||||
|
||||
# List of all files that are created by explicit building, editing, or
|
||||
# catenation.
|
||||
@ -459,6 +465,16 @@ stamp-ext: ${ext_headers}
|
||||
fi ;\
|
||||
$(STAMP) stamp-ext
|
||||
|
||||
|
||||
stamp-tr1: ${tr1_headers}
|
||||
@if [ ! -d "${tr1_builddir}" ]; then \
|
||||
mkdir -p ${tr1_builddir} ;\
|
||||
fi ;\
|
||||
if [ ! -f stamp-tr1 ]; then \
|
||||
(cd ${tr1_builddir} && $(LN_S) $? . || true) ;\
|
||||
fi ;\
|
||||
$(STAMP) stamp-tr1
|
||||
|
||||
stamp-debug: ${debug_headers}
|
||||
@if [ ! -d "${debug_builddir}" ]; then \
|
||||
mkdir -p ${debug_builddir} ;\
|
||||
@ -596,6 +612,9 @@ install-headers:
|
||||
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${ext_builddir}
|
||||
for file in ${ext_headers}; do \
|
||||
$(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${ext_builddir}; done
|
||||
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr1_builddir}
|
||||
for file in ${tr1_headers}; do \
|
||||
$(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr1_builddir}; done
|
||||
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir}
|
||||
for file in ${c_base_headers_rename}; do \
|
||||
$(INSTALL_DATA) ${c_base_builddir}/$${file} $(DESTDIR)${gxx_include_dir}/${c_base_builddir}; done
|
||||
|
@ -418,6 +418,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext
|
||||
ext_builddir = ./ext
|
||||
ext_headers = \
|
||||
${ext_srcdir}/algorithm \
|
||||
${ext_srcdir}/array_allocator.h \
|
||||
${ext_srcdir}/bitmap_allocator.h \
|
||||
${ext_srcdir}/debug_allocator.h \
|
||||
${ext_srcdir}/enc_filebuf.h \
|
||||
@ -441,6 +442,11 @@ ext_headers = \
|
||||
${ext_srcdir}/hash_fun.h \
|
||||
${ext_srcdir}/hashtable.h
|
||||
|
||||
tr1_srcdir = ${glibcxx_srcdir}/include/tr1
|
||||
tr1_builddir = ./tr1
|
||||
tr1_headers = \
|
||||
${tr1_srcdir}/array
|
||||
|
||||
|
||||
# This is the common subset of files that all three "C" header models use.
|
||||
c_base_srcdir = $(C_INCLUDE_DIR)
|
||||
@ -593,7 +599,7 @@ PCHFLAGS = -Winvalid-pch -Wno-deprecated -x c++-header $(CXXFLAGS)
|
||||
# CLEANFILES and all-local are kept up-to-date.
|
||||
allstamped = \
|
||||
stamp-std stamp-bits stamp-c_base stamp-c_compatibility \
|
||||
stamp-backward stamp-ext stamp-debug stamp-host
|
||||
stamp-backward stamp-ext stamp-tr1 stamp-debug stamp-host
|
||||
|
||||
|
||||
# List of all files that are created by explicit building, editing, or
|
||||
@ -841,6 +847,15 @@ stamp-ext: ${ext_headers}
|
||||
fi ;\
|
||||
$(STAMP) stamp-ext
|
||||
|
||||
stamp-tr1: ${tr1_headers}
|
||||
@if [ ! -d "${tr1_builddir}" ]; then \
|
||||
mkdir -p ${tr1_builddir} ;\
|
||||
fi ;\
|
||||
if [ ! -f stamp-tr1 ]; then \
|
||||
(cd ${tr1_builddir} && $(LN_S) $? . || true) ;\
|
||||
fi ;\
|
||||
$(STAMP) stamp-tr1
|
||||
|
||||
stamp-debug: ${debug_headers}
|
||||
@if [ ! -d "${debug_builddir}" ]; then \
|
||||
mkdir -p ${debug_builddir} ;\
|
||||
@ -972,6 +987,9 @@ install-headers:
|
||||
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${ext_builddir}
|
||||
for file in ${ext_headers}; do \
|
||||
$(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${ext_builddir}; done
|
||||
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr1_builddir}
|
||||
for file in ${tr1_headers}; do \
|
||||
$(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr1_builddir}; done
|
||||
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir}
|
||||
for file in ${c_base_headers_rename}; do \
|
||||
$(INSTALL_DATA) ${c_base_builddir}/$${file} $(DESTDIR)${gxx_include_dir}/${c_base_builddir}; done
|
||||
|
141
libstdc++-v3/include/ext/array_allocator.h
Normal file
141
libstdc++-v3/include/ext/array_allocator.h
Normal file
@ -0,0 +1,141 @@
|
||||
// array allocator -*- C++ -*-
|
||||
|
||||
// Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#ifndef _ARRAY_ALLOCATOR_H
|
||||
#define _ARRAY_ALLOCATOR_H 1
|
||||
|
||||
#include <cstddef>
|
||||
#include <new>
|
||||
#include <tr1/array>
|
||||
|
||||
namespace __gnu_cxx
|
||||
{
|
||||
template<typename _Tp>
|
||||
class array_allocator_base
|
||||
{
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef _Tp* pointer;
|
||||
typedef const _Tp* const_pointer;
|
||||
typedef _Tp& reference;
|
||||
typedef const _Tp& const_reference;
|
||||
typedef _Tp value_type;
|
||||
|
||||
pointer
|
||||
address(reference __x) const { return &__x; }
|
||||
|
||||
const_pointer
|
||||
address(const_reference __x) const { return &__x; }
|
||||
|
||||
void
|
||||
deallocate(pointer __p, size_type)
|
||||
{
|
||||
// Does nothing.
|
||||
}
|
||||
|
||||
size_type
|
||||
max_size() const throw()
|
||||
{ return size_t(-1) / sizeof(_Tp); }
|
||||
|
||||
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
||||
// 402. wrong new expression in [some_] allocator::construct
|
||||
void
|
||||
construct(pointer __p, const _Tp& __val)
|
||||
{ ::new(__p) value_type(__val); }
|
||||
|
||||
void
|
||||
destroy(pointer __p) { __p->~_Tp(); }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief An allocator that uses previously allocated memory.
|
||||
* This memory can be externally, globally, or otherwise allocated.
|
||||
*
|
||||
* (See @link Allocators allocators info @endlink for more.)
|
||||
*/
|
||||
template<typename _Tp, typename _Array = std::tr1::array<_Tp> >
|
||||
class array_allocator : public array_allocator_base<_Tp>
|
||||
{
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef _Tp* pointer;
|
||||
typedef const _Tp* const_pointer;
|
||||
typedef _Tp& reference;
|
||||
typedef const _Tp& const_reference;
|
||||
typedef _Tp value_type;
|
||||
|
||||
typedef _Array array_type;
|
||||
|
||||
array_type* _M_array;
|
||||
|
||||
template<typename _Tp1, typename _Array1 = _Array>
|
||||
struct rebind
|
||||
{ typedef array_allocator<_Tp1, _Array1> other; };
|
||||
|
||||
array_allocator(array_type* __array = NULL) throw()
|
||||
: _M_array(__array)
|
||||
{ }
|
||||
|
||||
array_allocator(const array_allocator& __o) throw()
|
||||
: _M_array(__o._M_array) { }
|
||||
|
||||
template<typename _Tp1, typename _Array1>
|
||||
array_allocator(const array_allocator<_Tp1, _Array1>&) throw()
|
||||
: _M_array(NULL) { }
|
||||
|
||||
~array_allocator() throw() { }
|
||||
|
||||
pointer
|
||||
allocate(size_type __n, const void* = 0)
|
||||
{
|
||||
static size_type used;
|
||||
if (__builtin_expect(used > array_type::_S_index, false))
|
||||
throw std::bad_alloc();
|
||||
pointer __ret = _M_array->begin() + used;
|
||||
used += __n;
|
||||
return __ret;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename _Tp, typename _Array>
|
||||
inline bool
|
||||
operator==(const array_allocator<_Tp, _Array>&,
|
||||
const array_allocator<_Tp, _Array>&)
|
||||
{ return true; }
|
||||
|
||||
template<typename _Tp, typename _Array>
|
||||
inline bool
|
||||
operator!=(const array_allocator<_Tp, _Array>&,
|
||||
const array_allocator<_Tp, _Array>&)
|
||||
{ return false; }
|
||||
} // namespace __gnu_cxx
|
||||
|
||||
#endif
|
200
libstdc++-v3/include/tr1/array
Normal file
200
libstdc++-v3/include/tr1/array
Normal file
@ -0,0 +1,200 @@
|
||||
// class template array -*- C++ -*-
|
||||
|
||||
// Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#ifndef _ARRAY
|
||||
#define _ARRAY 1
|
||||
|
||||
#include <new>
|
||||
#include <iterator>
|
||||
|
||||
//namespace std::tr1
|
||||
namespace std
|
||||
{
|
||||
namespace tr1
|
||||
{
|
||||
// [6.2.2] Class template array template
|
||||
// Requires complete type _Tp.
|
||||
// Use of char array allows _Tp to skirt default constructable requirement.
|
||||
template<typename _Tp, size_t _Nm = 1>
|
||||
struct array
|
||||
{
|
||||
enum { _S_index = _Nm };
|
||||
|
||||
typedef _Tp value_type;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef value_type* iterator;
|
||||
typedef const value_type* const_iterator;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
typedef char layout_type[sizeof(_Tp)] __attribute__ ((aligned(__alignof__(_Tp))));
|
||||
|
||||
layout_type _M_instance[_Nm];
|
||||
|
||||
// No explicit construct/copy/destroy for aggregate type.
|
||||
|
||||
void
|
||||
assign(const value_type& u);
|
||||
|
||||
void
|
||||
swap(array&);
|
||||
|
||||
// Iterators.
|
||||
iterator
|
||||
begin()
|
||||
{ return reinterpret_cast<iterator>(&_M_instance[0]); }
|
||||
|
||||
const_iterator
|
||||
begin() const
|
||||
{ return reinterpret_cast<const_iterator>(&_M_instance[0]); }
|
||||
|
||||
iterator
|
||||
end()
|
||||
{ return reinterpret_cast<iterator>(&_M_instance[_S_index - 1]); }
|
||||
|
||||
const_iterator
|
||||
end() const
|
||||
{ return reinterpret_cast<iterator>(&_M_instance[_S_index - 1]); }
|
||||
|
||||
reverse_iterator
|
||||
rbegin()
|
||||
{ return reverse_iterator(this->end()); }
|
||||
|
||||
const_reverse_iterator
|
||||
rbegin() const
|
||||
{ return const_reverse_iterator(this->end()); }
|
||||
|
||||
reverse_iterator
|
||||
rend()
|
||||
{ return reverse_iterator(this->begin()); }
|
||||
|
||||
const_reverse_iterator
|
||||
rend() const
|
||||
{ return const_reverse_iterator(this->begin()); }
|
||||
|
||||
// Capacity.
|
||||
size_type
|
||||
size() const { return _S_index; }
|
||||
|
||||
size_type
|
||||
max_size() const
|
||||
{
|
||||
// XXX Not specified. Unnecessary, this is fixed-size.
|
||||
return _S_index;
|
||||
}
|
||||
|
||||
bool
|
||||
empty() const;
|
||||
|
||||
// Element access.
|
||||
reference
|
||||
operator[](size_type __n)
|
||||
{ return reinterpret_cast<reference>(_M_instance[__n]); }
|
||||
|
||||
const_reference
|
||||
operator[](size_type __n) const
|
||||
{ return reinterpret_cast<const_reference>(_M_instance[__n]); }
|
||||
|
||||
const_reference
|
||||
at(size_type __n) const
|
||||
{
|
||||
if (__builtin_expect(__n > _S_index, false))
|
||||
throw std::bad_alloc();
|
||||
return reinterpret_cast<const_reference>(_M_instance[__n]);
|
||||
}
|
||||
|
||||
reference
|
||||
at(size_type __n)
|
||||
{
|
||||
if (__builtin_expect(__n > _S_index, false))
|
||||
throw std::bad_alloc();
|
||||
return reinterpret_cast<reference>(_M_instance[__n]);
|
||||
}
|
||||
|
||||
reference
|
||||
front();
|
||||
|
||||
const_reference
|
||||
front() const;
|
||||
|
||||
reference
|
||||
back();
|
||||
|
||||
const_reference
|
||||
back() const;
|
||||
|
||||
_Tp*
|
||||
data();
|
||||
|
||||
const _Tp*
|
||||
data() const;
|
||||
};
|
||||
|
||||
// Array comparisons.
|
||||
template<typename _Tp, size_t _Nm>
|
||||
bool
|
||||
operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
|
||||
{ return false; }
|
||||
|
||||
template<typename _Tp, size_t _Nm>
|
||||
bool
|
||||
operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
|
||||
{ return !(__one == __two); }
|
||||
|
||||
template<typename _Tp, size_t _Nm>
|
||||
bool
|
||||
operator<(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
|
||||
{ return false; }
|
||||
|
||||
template<typename _Tp, size_t _Nm>
|
||||
bool
|
||||
operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
|
||||
{ return false; }
|
||||
|
||||
template<typename _Tp, size_t _Nm>
|
||||
bool
|
||||
operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
|
||||
{ return false; }
|
||||
|
||||
template<typename _Tp, size_t _Nm>
|
||||
bool
|
||||
operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
|
||||
{ return false; }
|
||||
|
||||
// [6.2.2.2] Specialized algorithms.
|
||||
template<typename _Tp, size_t _Nm>
|
||||
void
|
||||
swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
|
||||
{ swap_ranges(__one.begin(), __one.end(), __two.begin()); }
|
||||
} // namespace std::tr1
|
||||
}
|
||||
|
||||
#endif
|
65
libstdc++-v3/testsuite/ext/array_allocator/1.cc
Normal file
65
libstdc++-v3/testsuite/ext/array_allocator/1.cc
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <ext/array_allocator.h>
|
||||
|
||||
typedef char char_type;
|
||||
typedef std::char_traits<char_type> traits_type;
|
||||
typedef std::tr1::array<char_type, 4> array_type;
|
||||
|
||||
array_type extern_array;
|
||||
|
||||
void test01()
|
||||
{
|
||||
using std::basic_string;
|
||||
typedef __gnu_cxx::array_allocator<char_type, array_type> allocator_type;
|
||||
typedef basic_string<char_type, traits_type, allocator_type> string_type;
|
||||
|
||||
allocator_type a(&extern_array);
|
||||
string_type s(a);
|
||||
|
||||
try
|
||||
{
|
||||
s.reserve(4); // Actually need 4 + 1 + sizeof(std::string::_Rep).
|
||||
}
|
||||
catch(std::bad_alloc& obj)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
72
libstdc++-v3/testsuite/ext/array_allocator/2.cc
Normal file
72
libstdc++-v3/testsuite/ext/array_allocator/2.cc
Normal file
@ -0,0 +1,72 @@
|
||||
// Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <ext/array_allocator.h>
|
||||
|
||||
typedef char char_type;
|
||||
typedef std::char_traits<char_type> traits_type;
|
||||
typedef std::tr1::array<char_type, 17> array_type;
|
||||
|
||||
array_type extern_array;
|
||||
|
||||
void test01()
|
||||
{
|
||||
using std::basic_string;
|
||||
typedef __gnu_cxx::array_allocator<char_type, array_type> allocator_type;
|
||||
typedef basic_string<char_type, traits_type, allocator_type> string_type;
|
||||
|
||||
size_t index = array_type::_S_index;
|
||||
allocator_type a(&extern_array);
|
||||
string_type s(a);
|
||||
|
||||
try
|
||||
{
|
||||
s.reserve(4); // Actually need 4 + 1 + sizeof(std::string::_Rep).
|
||||
}
|
||||
catch(std::bad_alloc& obj)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
s.append(1, 'c');
|
||||
s.append(2, 'b');
|
||||
|
||||
std::cout << s.c_str() << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user