This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[PATCH] Move rope, slist, hash_map, hash_set to __gnu_cxx
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: gdr at codesourcery dot com, ncm at cantrip dot org, bkoz at redhat dot com
- Date: Sun, 30 Dec 2001 10:20:08 +0100
- Subject: [PATCH] Move rope, slist, hash_map, hash_set to __gnu_cxx
Hi,
this one moves such estensions (i.e., all those already present in include/ext
before the recent addition of algorithm) to namespace __gnu_cxx. Tested
i686-pc-linux-gnu (*).
The patch is against the *current* mainline, therefore it calls
std::uninitialized_copy_n, not __gnu_cxx::uninitialized_copy_n. Indeed, if I
understand well some comments from Gaby, before moving such HP/SGI extensions,
currently present in stl_uninitialized.h, to __gnu_cxx it is better to first
clean up stl_deque.h, which uses some of them (Phil is working on this).
Cheers,
Paolo.
(*) I have also carried out some additional basic tests, which I will polish and
submit separately.
//////////
2001-12-30 Paolo Carlini <pcarlini@unitus.it>
* include/ext/hash_map: Move into __gnu_cxx, tweak, add using
declarations.
* include/ext/hash_set: Same.
* include/ext/ropeimpl.h: Same.
* include/ext/stl_hash_fun.h: Same.
* include/ext/stl_hashtable.h: Same.
* include/ext/stl_rope.h: Same.
diff -prN libstdc++-v3-orig/include/ext/hash_map
libstdc++-v3/include/ext/hash_map
*** libstdc++-v3-orig/include/ext/hash_map Tue Nov 20 01:51:37 2001
--- libstdc++-v3/include/ext/hash_map Sat Dec 29 16:05:42 2001
***************
*** 64,71 ****
#include <ext/stl_hashtable.h>
#include <bits/concept_check.h>
! namespace std
{
// Forward declaration of equality operator; needed for friend declaration.
--- 64,75 ----
#include <ext/stl_hashtable.h>
#include <bits/concept_check.h>
! namespace __gnu_cxx
{
+ using std::equal_to;
+ using std::allocator;
+ using std::pair;
+ using std::_Select1st;
// Forward declaration of equality operator; needed for friend declaration.
*************** swap(hash_multimap<_Key,_Tp,_HashFcn,_Eq
*** 371,384 ****
__hm1.swap(__hm2);
}
// Specialization of insert_iterator so that it will work for hash_map
// and hash_multimap.
template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
! class insert_iterator<hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
protected:
! typedef hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
_Container* container;
public:
typedef _Container container_type;
--- 375,391 ----
__hm1.swap(__hm2);
}
+ } // namespace __gnu_cxx
+ namespace std
+ {
// Specialization of insert_iterator so that it will work for hash_map
// and hash_multimap.
template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
! class insert_iterator<__gnu_cxx::hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>
> {
protected:
! typedef __gnu_cxx::hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
_Container* container;
public:
typedef _Container container_type;
*************** public:
*** 402,410 ****
};
template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
! class insert_iterator<hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
protected:
! typedef hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
_Container* container;
typename _Container::iterator iter;
public:
--- 409,417 ----
};
template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
! class insert_iterator<__gnu_cxx::hash_multimap<_Key, _Tp, _HashFn, _EqKey,
_Alloc> > {
protected:
! typedef __gnu_cxx::hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc>
_Container;
_Container* container;
typename _Container::iterator iter;
public:
diff -prN libstdc++-v3-orig/include/ext/hash_set
libstdc++-v3/include/ext/hash_set
*** libstdc++-v3-orig/include/ext/hash_set Tue Nov 20 01:51:37 2001
--- libstdc++-v3/include/ext/hash_set Sat Dec 29 16:06:20 2001
***************
*** 64,71 ****
#include <ext/stl_hashtable.h>
#include <bits/concept_check.h>
! namespace std
{
// Forward declaration of equality operator; needed for friend declaration.
--- 64,75 ----
#include <ext/stl_hashtable.h>
#include <bits/concept_check.h>
! namespace __gnu_cxx
{
+ using std::equal_to;
+ using std::allocator;
+ using std::pair;
+ using std::_Identity;
// Forward declaration of equality operator; needed for friend declaration.
*************** swap(hash_multiset<_Val,_HashFcn,_EqualK
*** 361,373 ****
__hs1.swap(__hs2);
}
// Specialization of insert_iterator so that it will work for hash_set
// and hash_multiset.
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
! class insert_iterator<hash_set<_Value, _HashFcn, _EqualKey, _Alloc> > {
protected:
! typedef hash_set<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
_Container* container;
public:
typedef _Container container_type;
--- 365,381 ----
__hs1.swap(__hs2);
}
+ } // namespace __gnu_cxx
+
+ namespace std
+ {
// Specialization of insert_iterator so that it will work for hash_set
// and hash_multiset.
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
! class insert_iterator<__gnu_cxx::hash_set<_Value, _HashFcn, _EqualKey, _Alloc>
> {
protected:
! typedef __gnu_cxx::hash_set<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
_Container* container;
public:
typedef _Container container_type;
*************** public:
*** 391,399 ****
};
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
! class insert_iterator<hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc> > {
protected:
! typedef hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
_Container* container;
typename _Container::iterator iter;
public:
--- 399,407 ----
};
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
! class insert_iterator<__gnu_cxx::hash_multiset<_Value, _HashFcn, _EqualKey,
_Alloc> > {
protected:
! typedef __gnu_cxx::hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>
_Container;
_Container* container;
typename _Container::iterator iter;
public:
diff -prN libstdc++-v3-orig/include/ext/ropeimpl.h
libstdc++-v3/include/ext/ropeimpl.h
*** libstdc++-v3-orig/include/ext/ropeimpl.h Thu Dec 13 01:41:02 2001
--- libstdc++-v3/include/ext/ropeimpl.h Sun Dec 30 08:46:59 2001
***************
*** 49,56 ****
#include <bits/std_iostream.h>
#include <bits/functexcept.h>
! namespace std
{
// Set buf_start, buf_end, and buf_ptr appropriately, filling tmp_buf
// if necessary. Assumes _M_path_end[leaf_index] and leaf_pos are correct.
--- 49,63 ----
#include <bits/std_iostream.h>
#include <bits/functexcept.h>
! namespace __gnu_cxx
{
+ using std::size_t;
+ using std::printf;
+ using std::basic_ostream;
+ using std::__throw_length_error;
+ using std::__alloc;
+ using std::_Destroy;
+ using std::uninitialized_copy_n;
// Set buf_start, buf_end, and buf_ptr appropriately, filling tmp_buf
// if necessary. Assumes _M_path_end[leaf_index] and leaf_pos are correct.
*************** basic_ostream<_CharT, _Traits>& operator
*** 901,907 ****
const rope<_CharT, _Alloc>& __r)
{
size_t __w = __o.width();
! bool __left = bool(__o.flags() & ios::left);
size_t __pad_len;
size_t __rope_len = __r.size();
_Rope_insert_char_consumer<_CharT, _Traits> __c(__o);
--- 908,914 ----
const rope<_CharT, _Alloc>& __r)
{
size_t __w = __o.width();
! bool __left = bool(__o.flags() & std::ios::left);
size_t __pad_len;
size_t __rope_len = __r.size();
_Rope_insert_char_consumer<_CharT, _Traits> __c(__o);
*************** rope<_CharT,_Alloc>::_S_flatten(_RopeRep
*** 974,980 ****
case _RopeRep::_S_leaf:
{
_RopeLeaf* __l = (_RopeLeaf*)__r;
! return copy_n(__l->_M_data, __l->_M_size, __buffer).second;
}
case _RopeRep::_S_function:
case _RopeRep::_S_substringfn:
--- 981,987 ----
case _RopeRep::_S_leaf:
{
_RopeLeaf* __l = (_RopeLeaf*)__r;
! return std::copy_n(__l->_M_data, __l->_M_size, __buffer).second;
}
case _RopeRep::_S_function:
case _RopeRep::_S_substringfn:
*************** const _CharT* rope<_CharT,_Alloc>::c_str
*** 1449,1455 ****
_M_tree_ptr->_M_c_string = __result;
# else
if ((__old_c_string = (__GC_CONST _CharT*)
! _Atomic_swap((unsigned long *)(&(_M_tree_ptr->_M_c_string)),
(unsigned long)__result)) != 0) {
// It must have been added in the interim. Hence it had to have been
// separately allocated. Deallocate the old copy, since we just
--- 1456,1462 ----
_M_tree_ptr->_M_c_string = __result;
# else
if ((__old_c_string = (__GC_CONST _CharT*)
! std::_Atomic_swap((unsigned long *)(&(_M_tree_ptr->_M_c_string)),
(unsigned long)__result)) != 0) {
// It must have been added in the interim. Hence it had to have been
// separately allocated. Deallocate the old copy, since we just
*************** inline void rotate(
*** 1530,1536 ****
}
# endif
! } // namespace std
// Local Variables:
// mode:C++
--- 1537,1543 ----
}
# endif
! } // namespace __gnu_cxx
// Local Variables:
// mode:C++
diff -prN libstdc++-v3-orig/include/ext/slist libstdc++-v3/include/ext/slist
*** libstdc++-v3-orig/include/ext/slist Tue Nov 20 01:51:37 2001
--- libstdc++-v3/include/ext/slist Sat Dec 29 18:59:18 2001
***************
*** 55,62 ****
#include <bits/stl_uninitialized.h>
#include <bits/concept_check.h>
! namespace std
{
struct _Slist_node_base
{
--- 55,68 ----
#include <bits/stl_uninitialized.h>
#include <bits/concept_check.h>
! namespace __gnu_cxx
{
+ using std::size_t;
+ using std::ptrdiff_t;
+ using std::_Alloc_traits;
+ using std::_Construct;
+ using std::_Destroy;
+ using std::allocator;
struct _Slist_node_base
{
*************** struct _Slist_node : public _Slist_node_
*** 145,153 ****
struct _Slist_iterator_base
{
! typedef size_t size_type;
! typedef ptrdiff_t difference_type;
! typedef forward_iterator_tag iterator_category;
_Slist_node_base* _M_node;
--- 151,159 ----
struct _Slist_iterator_base
{
! typedef size_t size_type;
! typedef ptrdiff_t difference_type;
! typedef std::forward_iterator_tag iterator_category;
_Slist_node_base* _M_node;
*************** class slist : private _Slist_base<_Tp,_A
*** 297,303 ****
private:
typedef _Slist_base<_Tp,_Alloc> _Base;
public:
! typedef _Tp value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
--- 303,309 ----
private:
typedef _Slist_base<_Tp,_Alloc> _Base;
public:
! typedef _Tp value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
*************** void slist<_Tp,_Alloc>::sort(_StrictWeak
*** 897,909 ****
}
}
// Specialization of insert_iterator so that insertions will be constant
// time rather than linear time.
template <class _Tp, class _Alloc>
! class insert_iterator<slist<_Tp, _Alloc> > {
protected:
! typedef slist<_Tp, _Alloc> _Container;
_Container* container;
typename _Container::iterator iter;
public:
--- 903,919 ----
}
}
+ } // namespace __gnu_cxx
+
+ namespace std
+ {
// Specialization of insert_iterator so that insertions will be constant
// time rather than linear time.
template <class _Tp, class _Alloc>
! class insert_iterator<__gnu_cxx::slist<_Tp, _Alloc> > {
protected:
! typedef __gnu_cxx::slist<_Tp, _Alloc> _Container;
_Container* container;
typename _Container::iterator iter;
public:
*************** public:
*** 932,938 ****
insert_iterator<_Container>& operator++(int) { return *this; }
};
! } // namespace std
#endif /* __SGI_STL_INTERNAL_SLIST_H */
--- 942,948 ----
insert_iterator<_Container>& operator++(int) { return *this; }
};
! } // namespace std
#endif /* __SGI_STL_INTERNAL_SLIST_H */
diff -prN libstdc++-v3-orig/include/ext/stl_hash_fun.h
libstdc++-v3/include/ext/stl_hash_fun.h
*** libstdc++-v3-orig/include/ext/stl_hash_fun.h Tue Nov 20 01:51:37 2001
--- libstdc++-v3/include/ext/stl_hash_fun.h Sat Dec 29 11:35:41 2001
***************
*** 63,70 ****
#include <bits/std_cstddef.h>
! namespace std
{
template <class _Key> struct hash { };
--- 63,71 ----
#include <bits/std_cstddef.h>
! namespace __gnu_cxx
{
+ using std::size_t;
template <class _Key> struct hash { };
*************** template<> struct hash<unsigned long> {
*** 115,121 ****
size_t operator()(unsigned long __x) const { return __x; }
};
! } // namespace std
#endif /* _CPP_BITS_STL_HASH_FUN_H */
--- 116,122 ----
size_t operator()(unsigned long __x) const { return __x; }
};
! } // namespace __gnu_cxx
#endif /* _CPP_BITS_STL_HASH_FUN_H */
diff -prN libstdc++-v3-orig/include/ext/stl_hashtable.h
libstdc++-v3/include/ext/stl_hashtable.h
*** libstdc++-v3-orig/include/ext/stl_hashtable.h Thu Dec 6 21:29:31 2001
--- libstdc++-v3/include/ext/stl_hashtable.h Sat Dec 29 16:57:54 2001
***************
*** 74,81 ****
#include <bits/stl_vector.h>
#include <ext/stl_hash_fun.h>
! namespace std
{
template <class _Val>
struct _Hashtable_node
--- 74,90 ----
#include <bits/stl_vector.h>
#include <ext/stl_hash_fun.h>
! namespace __gnu_cxx
{
+ using std::size_t;
+ using std::ptrdiff_t;
+ using std::forward_iterator_tag;
+ using std::input_iterator_tag;
+ using std::_Alloc_traits;
+ using std::_Construct;
+ using std::_Destroy;
+ using std::vector;
+ using std::pair;
template <class _Val>
struct _Hashtable_node
*************** struct _Hashtable_node
*** 85,91 ****
};
template <class _Val, class _Key, class _HashFcn,
! class _ExtractKey, class _EqualKey, class _Alloc = __alloc>
class hashtable;
template <class _Val, class _Key, class _HashFcn,
--- 94,100 ----
};
template <class _Val, class _Key, class _HashFcn,
! class _ExtractKey, class _EqualKey, class _Alloc = std::__alloc>
class hashtable;
template <class _Val, class _Key, class _HashFcn,
*************** inline unsigned long __stl_next_prime(un
*** 188,194 ****
{
const unsigned long* __first = __stl_prime_list;
const unsigned long* __last = __stl_prime_list + (int)__stl_num_primes;
! const unsigned long* pos = lower_bound(__first, __last, __n);
return pos == __last ? *(__last - 1) : *pos;
}
--- 197,203 ----
{
const unsigned long* __first = __stl_prime_list;
const unsigned long* __last = __stl_prime_list + (int)__stl_num_primes;
! const unsigned long* pos = std::lower_bound(__first, __last, __n);
return pos == __last ? *(__last - 1) : *pos;
}
*************** void hashtable<_Val,_Key,_HF,_Ex,_Eq,_Al
*** 964,970 ****
}
}
! } // namespace std
#endif /* __SGI_STL_INTERNAL_HASHTABLE_H */
--- 973,979 ----
}
}
! } // namespace __gnu_cxx
#endif /* __SGI_STL_INTERNAL_HASHTABLE_H */
diff -prN libstdc++-v3-orig/include/ext/stl_rope.h
libstdc++-v3/include/ext/stl_rope.h
*** libstdc++-v3-orig/include/ext/stl_rope.h Fri Dec 21 14:08:35 2001
--- libstdc++-v3/include/ext/stl_rope.h Sun Dec 30 09:51:36 2001
***************
*** 61,68 ****
# define __GC_CONST // constant except for deallocation
# endif
! namespace std
{
// The _S_eos function is used for those functions that
// convert to/from C-like strings to detect the end of the string.
--- 61,77 ----
# define __GC_CONST // constant except for deallocation
# endif
! namespace __gnu_cxx
{
+ using std::size_t;
+ using std::ptrdiff_t;
+ using std::allocator;
+ using std::iterator;
+ using std::reverse_iterator;
+ using std::_Alloc_traits;
+ using std::_Destroy;
+ using std::_Refcount_Base;
+ using std::uninitialized_copy_n;
// The _S_eos function is used for those functions that
// convert to/from C-like strings to detect the end of the string.
*************** class char_producer {
*** 122,128 ****
// little like containers.
template<class _Sequence, size_t _Buf_sz = 100>
! class sequence_buffer : public
iterator<output_iterator_tag,void,void,void,void>
{
public:
typedef typename _Sequence::value_type value_type;
--- 131,137 ----
// little like containers.
template<class _Sequence, size_t _Buf_sz = 100>
! class sequence_buffer : public
iterator<std::output_iterator_tag,void,void,void,void>
{
public:
typedef typename _Sequence::value_type value_type;
*************** rope<_CharT,_Alloc> operator+ (const rop
*** 316,322 ****
// The result has refcount 0.
template<class _CharT, class _Alloc>
struct _Rope_Concat_fn
! : public binary_function<rope<_CharT,_Alloc>, rope<_CharT,_Alloc>,
rope<_CharT,_Alloc> > {
rope<_CharT,_Alloc> operator() (const rope<_CharT,_Alloc>& __x,
const rope<_CharT,_Alloc>& __y) {
--- 325,331 ----
// The result has refcount 0.
template<class _CharT, class _Alloc>
struct _Rope_Concat_fn
! : public std::binary_function<rope<_CharT,_Alloc>, rope<_CharT,_Alloc>,
rope<_CharT,_Alloc> > {
rope<_CharT,_Alloc> operator() (const rope<_CharT,_Alloc>& __x,
const rope<_CharT,_Alloc>& __y) {
*************** struct _Rope_RopeConcatenation : public
*** 601,607 ****
allocator_type __a)
: _Rope_RopeRep<_CharT,_Alloc>(_S_concat,
! max(__l->_M_depth, __r->_M_depth) + 1,
false,
__l->_M_size + __r->_M_size, __a),
_M_left(__l), _M_right(__r)
--- 610,616 ----
allocator_type __a)
: _Rope_RopeRep<_CharT,_Alloc>(_S_concat,
! std::max(__l->_M_depth, __r->_M_depth) +
1,
false,
__l->_M_size + __r->_M_size, __a),
_M_left(__l), _M_right(__r)
*************** class _Rope_char_ptr_proxy {
*** 838,844 ****
template<class _CharT, class _Alloc>
class _Rope_iterator_base
! : public iterator<random_access_iterator_tag, _CharT>
{
friend class rope<_CharT,_Alloc>;
public:
--- 847,853 ----
template<class _CharT, class _Alloc>
class _Rope_iterator_base
! : public iterator<std::random_access_iterator_tag, _CharT>
{
friend class rope<_CharT,_Alloc>;
public:
*************** class rope : public _Rope_base<_CharT,_A
*** 1538,1544 ****
{
_CharT* __buf = _Data_allocate(_S_rounded_up_size(1));
! _Construct(__buf, __c);
try {
_M_tree_ptr = _S_new_RopeLeaf(__buf, 1, __a);
}
--- 1547,1553 ----
{
_CharT* __buf = _Data_allocate(_S_rounded_up_size(1));
! std::_Construct(__buf, __c);
try {
_M_tree_ptr = _S_new_RopeLeaf(__buf, 1, __a);
}
*************** class rope : public _Rope_base<_CharT,_A
*** 2107,2114 ****
size_type find(_CharT __c, size_type __pos = 0) const;
size_type find(const _CharT* __s, size_type __pos = 0) const {
size_type __result_pos;
! const_iterator __result = search(const_begin() + __pos,
const_end(),
! __s, __s + _S_char_ptr_len(__s));
__result_pos = __result.index();
# ifndef __STL_OLD_ROPE_SEMANTICS
if (__result_pos == size()) __result_pos = npos;
--- 2116,2124 ----
size_type find(_CharT __c, size_type __pos = 0) const;
size_type find(const _CharT* __s, size_type __pos = 0) const {
size_type __result_pos;
! const_iterator __result =
! std::search(const_begin() + __pos, const_end(),
! __s, __s + _S_char_ptr_len(__s));
__result_pos = __result.index();
# ifndef __STL_OLD_ROPE_SEMANTICS
if (__result_pos == size()) __result_pos = npos;
*************** inline bool operator!= (const _Rope_char
*** 2429,2436 ****
}
template<class _CharT, class _Traits, class _Alloc>
! basic_ostream<_CharT, _Traits>& operator<<
! (basic_ostream<_CharT, _Traits>& __o,
const rope<_CharT, _Alloc>& __r);
typedef rope<char> crope;
--- 2439,2446 ----
}
template<class _CharT, class _Traits, class _Alloc>
! std::basic_ostream<_CharT, _Traits>& operator<<
! (std::basic_ostream<_CharT, _Traits>&
__o,
const rope<_CharT, _Alloc>& __r);
typedef rope<char> crope;
*************** template<> struct hash<wrope>
*** 2475,2481 ****
}
};
! } // namespace std
# include <ext/ropeimpl.h>
--- 2485,2491 ----
}
};
! } // namespace __gnu_cxx
# include <ext/ropeimpl.h>
diff -prN libstdc++-v3-orig/src/ext-inst.cc libstdc++-v3/src/ext-inst.cc
*** libstdc++-v3-orig/src/ext-inst.cc Tue Dec 4 21:13:40 2001
--- libstdc++-v3/src/ext-inst.cc Sun Dec 30 08:50:00 2001
***************
*** 35,39 ****
namespace std
{
! template const unsigned long rope<char, std::allocator<char> >::_S_min_len;
} // namespace std
--- 35,40 ----
namespace std
{
! template
! const unsigned long __gnu_cxx::rope<char, std::allocator<char>
>::_S_min_len;
} // namespace std
diff -prN libstdc++-v3-orig/testsuite/ext/rope.cc
libstdc++-v3/testsuite/ext/rope.cc
*** libstdc++-v3-orig/testsuite/ext/rope.cc Wed Oct 3 23:19:31 2001
--- libstdc++-v3/testsuite/ext/rope.cc Sun Dec 30 08:52:44 2001
***************
*** 25,31 ****
void test01()
{
! std::crope foo;
foo += "bar";
const char* data = foo.c_str();
std::cout << data << std::endl;
--- 25,31 ----
void test01()
{
! __gnu_cxx::crope foo;
foo += "bar";
const char* data = foo.c_str();
std::cout << data << std::endl;