Commit 390e4c0d by Benjamin Kosnik Committed by Benjamin Kosnik

c++config (_GLIBCXX_STD): New.


2004-04-16  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/c++config (_GLIBCXX_STD): New.
	* src/list.cc: Use it.
	* include/std/std_bitset.h: Same.
	* include/bits/vector.tcc: Same.
	* include/bits/stl_set.h: Same.
	* include/bits/stl_multiset.h: Same.
	* include/bits/stl_multimap.h: Same.
	* include/bits/stl_map.h: Same.
	* include/bits/stl_list.h: Same.
	* include/bits/stl_vector.h: Same.
	* include/bits/stl_bvector.h: Same.
	* include/bits/stl_deque.h: Same.
	* include/bits/deque.tcc: Same.
	* include/bits/list.tcc: Same.
	* include/debug/vector: Same.
	* include/debug/set.h: Same.
	* include/debug/multiset.h: Same.
	* include/debug/multimap.h: Same.
	* include/debug/map.h: Same.
	* include/debug/list: Same.
	* include/debug/deque: Same.
	* include/debug/bitset: Same.
	* include/debug/formatter.h (__gnu_debug): Remove using directive.
	Add using declaration for std::type_info.
	* include/debug/safe_iterator.h: Add using declaration for
	std::iterator_traits and std::pair.
	* src/debug_list.cc: New.
	* src/Makefile.am: Add debug_list.cc.
	* src/Makefile.in: Regenerate.
	* config/linker-map.gnu: Add _List_node_base exports for std and
	__gnu_norm.

	* include/bits/stl_bvector.h (_Bvector_base): Use _Bvector_impl
	idiom that other containers use.
	* testsuite/23_containers/vector/bool/clear_allocator.cc: New.

From-SVN: r80763
parent 31e632d3
2004-04-16 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/c++config (_GLIBCXX_STD): New.
* src/list.cc: Use it.
* include/std/std_bitset.h: Same.
* include/bits/vector.tcc: Same.
* include/bits/stl_set.h: Same.
* include/bits/stl_multiset.h: Same.
* include/bits/stl_multimap.h: Same.
* include/bits/stl_map.h: Same.
* include/bits/stl_list.h: Same.
* include/bits/stl_vector.h: Same.
* include/bits/stl_bvector.h: Same.
* include/bits/stl_deque.h: Same.
* include/bits/deque.tcc: Same.
* include/bits/list.tcc: Same.
* include/debug/vector: Same.
* include/debug/set.h: Same.
* include/debug/multiset.h: Same.
* include/debug/multimap.h: Same.
* include/debug/map.h: Same.
* include/debug/list: Same.
* include/debug/deque: Same.
* include/debug/bitset: Same.
* include/debug/formatter.h (__gnu_debug): Remove using directive.
Add using declaration for std::type_info.
* include/debug/safe_iterator.h: Add using declaration for
std::iterator_traits and std::pair.
* src/debug_list.cc: New.
* src/Makefile.am: Add debug_list.cc.
* src/Makefile.in: Regenerate.
* config/linker-map.gnu: Add _List_node_base exports for std and
__gnu_norm.
* include/bits/stl_bvector.h (_Bvector_base): Use _Bvector_impl
idiom that other containers use.
* testsuite/23_containers/vector/bool/clear_allocator.cc: New.
2004-04-16 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/14975
......
......@@ -44,7 +44,7 @@ DIST_COMMON = README $(am__configure_deps) $(srcdir)/../config.guess \
$(top_srcdir)/configure $(top_srcdir)/fragment.am \
$(top_srcdir)/scripts/check_survey.in \
$(top_srcdir)/scripts/testsuite_flags.in ../ABOUT-NLS \
../COPYING ../COPYING.LIB ../ChangeLog ../README \
../COPYING ../COPYING.LIB ../ChangeLog ../README ../compile \
../config.guess ../config.rpath ../config.sub ../install-sh \
../ltcf-c.sh ../ltcf-cxx.sh ../ltcf-gcj.sh ../ltconfig \
../ltmain.sh ../missing ../mkinstalldirs ../ylwrap ChangeLog \
......
......@@ -55,6 +55,11 @@ GLIBCXX_3.4 {
std::locale::_S_normalize_category*;
std::locale::_[T-Za-z]*;
std::[A-Zm-z]*;
std::_List_node_base::hook*;
std::_List_node_base::swap*;
std::_List_node_base::unhook*;
std::_List_node_base::reverse*;
std::_List_node_base::transfer*;
std::__throw_*;
std::__basic_file*;
std::__timepunct*;
......@@ -66,10 +71,14 @@ GLIBCXX_3.4 {
std::__moneypunct_cache*;
std::__numpunct_cache*;
std::__timepunct_cache*;
__gnu_norm::*;
__gnu_debug::_Safe_iterator_base*;
__gnu_debug::_Safe_sequence_base*;
__gnu_debug::_Error_formatter*
__gnu_debug::_Error_formatter*;
__gnu_norm::_List_node_base::hook*;
__gnu_norm::_List_node_base::swap*;
__gnu_norm::_List_node_base::unhook*;
__gnu_norm::_List_node_base::reverse*;
__gnu_norm::_List_node_base::transfer*
};
# Names not in an 'extern' block are mangled names.
......
// Predefined symbols and macros -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -51,27 +51,30 @@
# define _GLIBCXX_EXTERN_TEMPLATE 1
#endif
// To enable debug mode.
namespace __gnu_norm
{
using namespace std;
}
// Debug mode support. Debug mode basic_string is not allowed to be
// associated with std, because of locale and exception link
// dependence.
namespace __gnu_debug_def { }
namespace __gnu_debug
{
using namespace __gnu_debug_def __attribute__ ((strong));
using namespace __gnu_debug_def;
}
#ifdef _GLIBCXX_DEBUG
# define _GLIBCXX_STD __gnu_norm
namespace __gnu_norm
{
using namespace std;
}
namespace std
{
#ifdef _GLIBCXX_DEBUG
using namespace __gnu_debug_def __attribute__ ((strong));
}
#else
using namespace __gnu_norm __attribute__ ((strong));
# define _GLIBCXX_STD std
#endif
}
// The remainder of the prewritten config is automatic; all the
// user hooks are listed above.
......
......@@ -61,7 +61,7 @@
#ifndef _DEQUE_TCC
#define _DEQUE_TCC 1
namespace __gnu_norm
namespace _GLIBCXX_STD
{
template <typename _Tp, typename _Alloc>
deque<_Tp,_Alloc>&
......@@ -714,6 +714,6 @@ namespace __gnu_norm
this->_M_impl._M_start._M_set_node(__new_nstart);
this->_M_impl._M_finish._M_set_node(__new_nstart + __old_num_nodes - 1);
}
} // namespace __gnu_norm
} // namespace std
#endif
......@@ -61,7 +61,7 @@
#ifndef _LIST_TCC
#define _LIST_TCC 1
namespace __gnu_norm
namespace _GLIBCXX_STD
{
template<typename _Tp, typename _Alloc>
void
......@@ -371,7 +371,7 @@ namespace __gnu_norm
swap( *(__fill-1) );
}
}
} // namespace __gnu_norm
} // namespace std
#endif /* _LIST_TCC */
......@@ -65,7 +65,7 @@
#include <bits/stl_iterator_base_types.h>
#include <bits/stl_iterator_base_funcs.h>
namespace __gnu_norm
namespace _GLIBCXX_STD
{
/**
* @if maint
......@@ -1496,6 +1496,6 @@ namespace __gnu_norm
inline void
swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
{ __x.swap(__y); }
} // namespace __gnu_norm
} // namespace std
#endif /* _DEQUE_H */
......@@ -63,7 +63,7 @@
#include <bits/concept_check.h>
namespace __gnu_norm
namespace _GLIBCXX_STD
{
// Supporting structures are split into common and templated types; the
// latter publicly inherits from the former in an effort to reduce code
......@@ -1247,7 +1247,7 @@ namespace __gnu_norm
inline void
swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
{ __x.swap(__y); }
} // namespace __gnu_norm
} // namespace std
#endif /* _LIST_H */
......@@ -63,7 +63,7 @@
#include <bits/concept_check.h>
namespace __gnu_norm
namespace _GLIBCXX_STD
{
/**
* @brief A standard container made up of (key,value) pairs, which can be
......@@ -689,6 +689,6 @@ namespace __gnu_norm
inline void
swap(map<_Key,_Tp,_Compare,_Alloc>& __x, map<_Key,_Tp,_Compare,_Alloc>& __y)
{ __x.swap(__y); }
} // namespace __gnu_norm
} // namespace std
#endif /* _MAP_H */
......@@ -63,7 +63,7 @@
#include <bits/concept_check.h>
namespace __gnu_norm
namespace _GLIBCXX_STD
{
// Forward declaration of operators < and ==, needed for friend declaration.
......@@ -673,6 +673,6 @@ namespace __gnu_norm
swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x,
multimap<_Key,_Tp,_Compare,_Alloc>& __y)
{ __x.swap(__y); }
} // namespace __gnu_norm
} // namespace std
#endif /* _MULTIMAP_H */
......@@ -63,7 +63,7 @@
#include <bits/concept_check.h>
namespace __gnu_norm
namespace _GLIBCXX_STD
{
// Forward declaration of operators < and ==, needed for friend declaration.
......@@ -580,6 +580,6 @@ namespace __gnu_norm
multiset<_Key,_Compare,_Alloc>& __y)
{ __x.swap(__y); }
} // namespace __gnu_norm
} // namespace std
#endif /* _MULTISET_H */
......@@ -63,7 +63,7 @@
#include <bits/concept_check.h>
namespace __gnu_norm
namespace _GLIBCXX_STD
{
// Forward declarations of operators < and ==, needed for friend declaration.
template<class _Key, class _Compare = less<_Key>,
......@@ -588,6 +588,6 @@ namespace __gnu_norm
swap(set<_Key,_Compare,_Alloc>& __x, set<_Key,_Compare,_Alloc>& __y)
{ __x.swap(__y); }
} // namespace __gnu_norm
} // namespace std
#endif /* _SET_H */
......@@ -65,7 +65,7 @@
#include <bits/functexcept.h>
#include <bits/concept_check.h>
namespace __gnu_norm
namespace _GLIBCXX_STD
{
/**
* @if maint
......@@ -927,6 +927,6 @@ namespace __gnu_norm
inline void
swap(vector<_Tp,_Alloc>& __x, vector<_Tp,_Alloc>& __y)
{ __x.swap(__y); }
} // namespace __gnu_norm
} // namespace std
#endif /* _VECTOR_H */
......@@ -61,7 +61,7 @@
#ifndef _VECTOR_TCC
#define _VECTOR_TCC 1
namespace __gnu_norm
namespace _GLIBCXX_STD
{
template<typename _Tp, typename _Alloc>
void
......@@ -409,6 +409,6 @@ namespace __gnu_norm
}
}
}
} // namespace __gnu_norm
} // namespace std
#endif /* _VECTOR_TCC */
// Debugging bitset implementation -*- C++ -*-
// Copyright (C) 2003
// Copyright (C) 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -39,9 +39,10 @@ namespace __gnu_debug_def
{
template<size_t _Nb>
class bitset
: public __gnu_norm::bitset<_Nb>, public __gnu_debug::_Safe_sequence_base
: public _GLIBCXX_STD::bitset<_Nb>,
public __gnu_debug::_Safe_sequence_base
{
typedef __gnu_norm::bitset<_Nb> _Base;
typedef _GLIBCXX_STD::bitset<_Nb> _Base;
typedef __gnu_debug::_Safe_sequence_base _Safe_base;
public:
......
// Debugging deque implementation -*- C++ -*-
// Copyright (C) 2003
// Copyright (C) 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -39,10 +39,10 @@ namespace __gnu_debug_def
{
template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
class deque
: public __gnu_norm::deque<_Tp, _Allocator>,
public __gnu_debug::_Safe_sequence<deque<_Tp, _Allocator> >
: public _GLIBCXX_STD::deque<_Tp, _Allocator>,
public __gnu_debug::_Safe_sequence<deque<_Tp, _Allocator> >
{
typedef __gnu_norm::deque<_Tp, _Allocator> _Base;
typedef _GLIBCXX_STD::deque<_Tp, _Allocator> _Base;
typedef __gnu_debug::_Safe_sequence<deque> _Safe_base;
public:
......
// Debug-mode error formatting implementation -*- C++ -*-
// Copyright (C) 2003
// Copyright (C) 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -36,7 +36,7 @@
namespace __gnu_debug
{
using namespace std;
using std::type_info;
/** Determine if the two types are the same. */
template<typename _Type1, typename _Type2>
......
// Debugging list implementation -*- C++ -*-
// Copyright (C) 2003
// Copyright (C) 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -40,10 +40,10 @@ namespace __gnu_debug_def
{
template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
class list
: public __gnu_norm::list<_Tp, _Allocator>,
: public _GLIBCXX_STD::list<_Tp, _Allocator>,
public __gnu_debug::_Safe_sequence<list<_Tp, _Allocator> >
{
typedef __gnu_norm::list<_Tp, _Allocator> _Base;
typedef _GLIBCXX_STD::list<_Tp, _Allocator> _Base;
typedef __gnu_debug::_Safe_sequence<list> _Safe_base;
public:
......@@ -76,7 +76,7 @@ namespace __gnu_debug_def
template<class _InputIterator>
list(_InputIterator __first, _InputIterator __last,
const _Allocator& __a = _Allocator())
: _Base(__gnu_debug::__check_valid_range(__first, __last), __last, __a)
: _Base(__gnu_debug::__check_valid_range(__first, __last), __last, __a)
{ }
......
// Debugging map implementation -*- C++ -*-
// Copyright (C) 2003
// Copyright (C) 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -40,10 +40,10 @@ namespace __gnu_debug_def
template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
class map
: public __gnu_norm::map<_Key, _Tp, _Compare, _Allocator>,
: public _GLIBCXX_STD::map<_Key, _Tp, _Compare, _Allocator>,
public __gnu_debug::_Safe_sequence<map<_Key, _Tp, _Compare, _Allocator> >
{
typedef __gnu_norm::map<_Key, _Tp, _Compare, _Allocator> _Base;
typedef _GLIBCXX_STD::map<_Key, _Tp, _Compare, _Allocator> _Base;
typedef __gnu_debug::_Safe_sequence<map> _Safe_base;
public:
......
// Debugging multimap implementation -*- C++ -*-
// Copyright (C) 2003
// Copyright (C) 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -40,10 +40,10 @@ namespace __gnu_debug_def
template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
class multimap
: public __gnu_norm::multimap<_Key, _Tp, _Compare, _Allocator>,
: public _GLIBCXX_STD::multimap<_Key, _Tp, _Compare, _Allocator>,
public __gnu_debug::_Safe_sequence<multimap<_Key,_Tp,_Compare,_Allocator> >
{
typedef __gnu_norm::multimap<_Key, _Tp, _Compare, _Allocator> _Base;
typedef _GLIBCXX_STD::multimap<_Key, _Tp, _Compare, _Allocator> _Base;
typedef __gnu_debug::_Safe_sequence<multimap> _Safe_base;
public:
......
// Debugging multiset implementation -*- C++ -*-
// Copyright (C) 2003
// Copyright (C) 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -40,10 +40,10 @@ namespace __gnu_debug_def
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Allocator = std::allocator<_Key> >
class multiset
: public __gnu_norm::multiset<_Key, _Compare, _Allocator>,
: public _GLIBCXX_STD::multiset<_Key, _Compare, _Allocator>,
public __gnu_debug::_Safe_sequence<multiset<_Key, _Compare, _Allocator> >
{
typedef __gnu_norm::multiset<_Key, _Compare, _Allocator> _Base;
typedef _GLIBCXX_STD::multiset<_Key, _Compare, _Allocator> _Base;
typedef __gnu_debug::_Safe_sequence<multiset> _Safe_base;
public:
......
// Safe iterator implementation -*- C++ -*-
// Copyright (C) 2003
// Copyright (C) 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -38,6 +38,9 @@
namespace __gnu_debug
{
using std::iterator_traits;
using std::pair;
/** Iterators that derive from _Safe_iterator_base but that aren't
* _Safe_iterators can be determined singular or non-singular via
* _Safe_iterator_base.
......
// Debugging set implementation -*- C++ -*-
// Copyright (C) 2003
// Copyright (C) 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -40,10 +40,10 @@ namespace __gnu_debug_def
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Allocator = std::allocator<_Key> >
class set
: public __gnu_norm::set<_Key,_Compare,_Allocator>,
: public _GLIBCXX_STD::set<_Key,_Compare,_Allocator>,
public __gnu_debug::_Safe_sequence<set<_Key, _Compare, _Allocator> >
{
typedef __gnu_norm::set<_Key,_Compare,_Allocator> _Base;
typedef _GLIBCXX_STD::set<_Key,_Compare,_Allocator> _Base;
typedef __gnu_debug::_Safe_sequence<set> _Safe_base;
public:
......
// Debugging vector implementation -*- C++ -*-
// Copyright (C) 2003
// Copyright (C) 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -41,10 +41,10 @@ namespace __gnu_debug_def
template<typename _Tp,
typename _Allocator = std::allocator<_Tp> >
class vector
: public __gnu_norm::vector<_Tp, _Allocator>,
: public _GLIBCXX_STD::vector<_Tp, _Allocator>,
public __gnu_debug::_Safe_sequence<vector<_Tp, _Allocator> >
{
typedef __gnu_norm::vector<_Tp, _Allocator> _Base;
typedef _GLIBCXX_STD::vector<_Tp, _Allocator> _Base;
typedef __gnu_debug::_Safe_sequence<vector> _Safe_base;
typedef typename _Base::const_iterator _Base_const_iterator;
......
......@@ -59,12 +59,11 @@
#include <ostream> // For ostream (operator<<)
#include <istream> // For istream (operator>>)
#define _GLIBCXX_BITSET_BITS_PER_WORD numeric_limits<unsigned long>::digits
#define _GLIBCXX_BITSET_WORDS(__n) \
((__n) < 1 ? 0 : ((__n) + _GLIBCXX_BITSET_BITS_PER_WORD - 1)/_GLIBCXX_BITSET_BITS_PER_WORD)
namespace __gnu_norm
namespace _GLIBCXX_STD
{
/**
* @if maint
......@@ -1218,7 +1217,7 @@ namespace __gnu_norm
return __os << __tmp;
}
//@}
} // namespace __gnu_norm
} // namespace std
#undef _GLIBCXX_BITSET_WORDS
#undef _GLIBCXX_BITSET_BITS_PER_WORD
......
......@@ -101,6 +101,7 @@ sources = \
complex_io.cc \
ctype.cc \
debug.cc \
debug_list.cc \
functexcept.cc \
globals_locale.cc \
globals_io.cc \
......
......@@ -59,12 +59,12 @@ am__objects_1 = atomicity.lo codecvt_members.lo collate_members.lo \
numeric_members.lo time_members.lo
am__objects_2 = basic_file.lo c++locale.lo
am__objects_3 = allocator.lo codecvt.lo complex_io.lo ctype.lo \
debug.lo functexcept.lo globals_locale.lo globals_io.lo ios.lo \
ios_failure.lo ios_init.lo ios_locale.lo limits.lo list.lo \
locale.lo locale_init.lo locale_facets.lo localename.lo \
stdexcept.lo strstream.lo tree.lo allocator-inst.lo \
concept-inst.lo fstream-inst.lo ext-inst.lo io-inst.lo \
istream-inst.lo locale-inst.lo locale-misc-inst.lo \
debug.lo debug_list.lo functexcept.lo globals_locale.lo \
globals_io.lo ios.lo ios_failure.lo ios_init.lo ios_locale.lo \
limits.lo list.lo locale.lo locale_init.lo locale_facets.lo \
localename.lo stdexcept.lo strstream.lo tree.lo \
allocator-inst.lo concept-inst.lo fstream-inst.lo ext-inst.lo \
io-inst.lo istream-inst.lo locale-inst.lo locale-misc-inst.lo \
misc-inst.lo ostream-inst.lo sstream-inst.lo streambuf-inst.lo \
string-inst.lo valarray-inst.lo wlocale-inst.lo \
wstring-inst.lo $(am__objects_1) $(am__objects_2)
......@@ -299,6 +299,7 @@ sources = \
complex_io.cc \
ctype.cc \
debug.cc \
debug_list.cc \
functexcept.cc \
globals_locale.cc \
globals_io.cc \
......
// Debugging mode support code for list -*- 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.
#define _GLIBCXX_DEBUG
#include <bits/c++config.h>
#include "list.cc"
......@@ -55,7 +55,7 @@
#include <list>
namespace __gnu_norm
namespace _GLIBCXX_STD
{
void
_List_node_base::swap(_List_node_base& __x, _List_node_base& __y)
......@@ -121,7 +121,7 @@ namespace __gnu_norm
}
void
_List_node_base::hook(_List_node_base * const __position)
_List_node_base::hook(_List_node_base* const __position)
{
this->_M_next = __position;
this->_M_prev = __position->_M_prev;
......@@ -137,5 +137,5 @@ namespace __gnu_norm
__prev_node->_M_next = __next_node;
__next_node->_M_prev = __prev_node;
}
} // namespace __gnu_norm
} // namespace std
// 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.
#include <vector>
#include <ext/new_allocator.h>
using namespace std;
using __gnu_cxx::new_allocator;
template<typename T>
class clear_alloc : public new_allocator<T>
{
public:
template <typename T1>
struct rebind
{ typedef clear_alloc<T1> other; };
virtual void clear() throw()
{ }
clear_alloc() throw()
{ }
clear_alloc(clear_alloc const& _wa) throw()
{ }
template<typename T1>
clear_alloc(clear_alloc<T1> const& _wa) throw()
{ }
virtual ~clear_alloc() throw()
{ this->clear(); }
T* allocate(typename new_allocator<T>::size_type n, const void *hint = 0)
{
this->clear();
return new_allocator<T>::allocate(n, hint);
}
void deallocate(T *ptr, typename new_allocator<T>::size_type n)
{
this->clear();
new_allocator<T>::deallocate(ptr, n);
}
};
template<typename Container>
void Check_Container()
{
Container* pic = new Container;
int x = 230;
while (x--)
{
pic->push_back(x);
}
pic->get_allocator();
// The following has led to infinite recursions or cores.
pic->clear();
delete pic;
}
int main()
{
Check_Container<std::vector<bool, clear_alloc<bool> > >();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment