Kaydet (Commit) 26b07b05 authored tarafından Herbert Dürr's avatar Herbert Dürr

#i122208# update STL header wrappers

From a binary perspective the wrappers allow dropping stlport4 itself
immediately and replacing it by standard compliant system or compiler
standard template libraries.

From a source code perspective the other parts of the codebase
can remain untouched for now. They can be gradually converted
from stlport4 to the TR1 or C++11 standard at a comfortable pace
later. The header wrappers will assist this source-code conversion.
üst d2c3483a
...@@ -46,6 +46,9 @@ $(INCCOM)$/stlport$/hash_map \ ...@@ -46,6 +46,9 @@ $(INCCOM)$/stlport$/hash_map \
$(INCCOM)$/stlport$/hash_set \ $(INCCOM)$/stlport$/hash_set \
$(INCCOM)$/stlport$/numeric \ $(INCCOM)$/stlport$/numeric \
$(INCCOM)$/stlport$/slist \ $(INCCOM)$/stlport$/slist \
$(INCCOM)$/stlport$/list \
$(INCCOM)$/stlport$/map \
$(INCCOM)$/stlport$/set \
$(INCCOM)$/stlport$/vector: systemstl$/$$(@:f) $(INCCOM)$/stlport$/vector: systemstl$/$$(@:f)
$(MKDIRHIER) $(@:d) $(MKDIRHIER) $(@:d)
$(COPY) $< $@ $(COPY) $< $@
......
...@@ -22,35 +22,51 @@ ...@@ -22,35 +22,51 @@
#ifndef SYSTEM_STL_FUNCTIONAL #ifndef SYSTEM_STL_FUNCTIONAL
#define SYSTEM_STL_FUNCTIONAL #define SYSTEM_STL_FUNCTIONAL
#ifdef GCC #if defined(HAVE_STL_INCLUDE_PATH)
# ifdef __MINGW32__ // TODO: use computed include file name
# define _SYSTEM_STL_MAKE_HEADER(path,header) <path/header> #include_next <functional>
# include _SYSTEM_STL_MAKE_HEADER(GXX_INCLUDE_PATH,functional) #elif defined(_MSC_VER)
# else #include <../../VC/include/functional>
# include <ext/../functional> namespace std { using tr1::hash; }
# endif #if 1 // TODO: enable only when std::_Swap_adl is not available
# include <ext/functional> // note: VS2008SP1 has known problems after a security update (KB971092,KB974479,KB974223)
namespace std{ template<class _T> void _Swap_adl(_T& l, _T& r) {swap(l,r);} }
#endif
#else // fall back to boost/tr1
#include <boost/tr1/tr1/functional>
#include <boost/functional/hash.hpp>
#endif
#ifndef NO_STLPORT4_EMULATION
namespace std namespace std
{ {
using __gnu_cxx::project1st; // emulate SGI extensions to the STL using http://www.sgi.com/tech/stl/stl_function.h as reference
using __gnu_cxx::project2nd; template< typename T> struct identity : unary_function<T,T> { T operator()(const T& t) const { return t;} };
using __gnu_cxx::select1st; template< typename T, typename U> struct project2nd : public binary_function<T,U,U> { U operator()(const T&, const U& u) const { return u;}};
using __gnu_cxx::select2nd; template<typename P> struct select1st : public unary_function<P, typename P::first_type> { const typename P::first_type& operator()(const P& p) const { return p.first; }};
using __gnu_cxx::compose1; template<typename P> struct select2nd : public unary_function<P, typename P::second_type> { const typename P::second_type& operator()(const P& p) const { return p.second; }};
using __gnu_cxx::compose2;
using __gnu_cxx::unary_compose; #if (defined(_MSC_VER) && (_MSC_VER >= 1600)) || defined(__GXX_EXPERIMENTAL_CXX0X__)
using __gnu_cxx::binary_compose; template<typename T> inline T&& forward( typename identity<T>::type&& t) { return t; }
# ifndef __GXX_EXPERIMENTAL_CXX0X__ #endif // C++11 move semantics
using __gnu_cxx::identity;
using __gnu_cxx::mem_fun1; template<typename Op1, typename Op2> class unary_compose : public unary_function<typename Op2::argument_type, typename Op1::result_type>
using __gnu_cxx::mem_fun1_ref; {
# endif protected:
} Op1 aOp1;
Op2 aOp2;
#else public:
# error UNSUPPORTED COMPILER unary_compose( const Op1& rOp1, const Op2& rOp2) : aOp1(rOp1), aOp2(rOp2) {}
#endif typename Op1::result_type operator()( const typename Op2::argument_type& x) const { return aOp1(aOp2(x)); }
};
template<typename Op1, typename Op2> inline unary_compose<Op1,Op2> compose1( const Op1& rOp1, const Op2& rOp2) { return unary_compose<Op1,Op2>(rOp1, rOp2); }
} // namespace std
#endif // NO_STLPORT4_EMULATION
#endif #endif
/* vi:set tabstop=4 shiftwidth=4 expandtab: */
...@@ -22,54 +22,91 @@ ...@@ -22,54 +22,91 @@
#ifndef SYSTEM_STL_HASHMAP #ifndef SYSTEM_STL_HASHMAP
#define SYSTEM_STL_HASHMAP #define SYSTEM_STL_HASHMAP
#ifdef GCC #ifdef HAVE_STL_INCLUDE_PATH
// TODO: use computed include file name
#include_next <unordered_map>
#elif defined(_MSC_VER)
#include <../../VC/include/unordered_map>
#define STLP4_EMUBASE_NS ::std::tr1
#else // fall back to boost/tr1
#include <boost/tr1/tr1/unordered_map>
#define STLP4_EMUBASE_NS ::boost
#endif
# include <functional>
# define _BACKWARD_BACKWARD_WARNING_H 1 #ifndef NO_STLPORT4_EMULATION
# include <ext/hash_map>
# undef _BACKWARD_BACKWARD_WARNING_H
namespace __gnu_cxx namespace std
{ {
template<> struct hash < std::string > #ifdef STLP4_EMUBASE_NS
{ using STLP4_EMUBASE_NS::hash;
size_t operator()(const std::string & x) const using STLP4_EMUBASE_NS::unordered_map;
{ using STLP4_EMUBASE_NS::unordered_multimap;
return hash< const char* >()(x.c_str()); #undef STLP4_EMUBASE_NS
} #endif
};
template<> struct hash< long long int >
{
size_t operator()(long long int __x) const
{
return __x;
}
};
template<> struct hash< unsigned long long int >
{
size_t operator()(unsigned long long int __x) const
{
return __x;
}
};
}
namespace std
template<
typename __K,
typename __T,
typename __H = hash<__K>,
typename __E = equal_to<__K>,
typename __A = allocator<pair<__K,__T> > >
class hash_map
: public unordered_map<__K,__T,__H,__E,__A>
{
public:
typedef unordered_map<__K,__T,__H,__E,__A> _super;
typedef __T data_type;
hash_map( void) {}
hash_map( size_t n) : _super( n) {}
#ifdef BOOST_TR1_UNORDERED_MAP_INCLUDED // workaround pre-BOOST_UNORDERED_USE_MOVE problem
// in derived classes the copy assignment operator can only be declared implicitly if
// its base class's assignment operator has the canonical signature.
// boost's assignment operators don't have this canonical signature when move-semantics are enabled
hash_map& operator=( const hash_map& r) { hash_map c(r); this->swap(c); return *this; }
#endif
void resize( size_t n) { _super::rehash(n); }
private:
// setting the hasher dynamically is not supported in the emulation!
hash_map( size_t, const __H&, const __E& rE=__E(), const __A& rA=__A()); // not implemented
};
template<
typename __K,
typename __T,
typename __H = hash<__K>,
typename __E = equal_to<__K>,
typename __A = allocator<pair<__K,__T> > >
class hash_multimap
: public unordered_multimap<__K,__T,__H,__E,__A>
{ {
# ifndef __GXX_EXPERIMENTAL_CXX0X__ public:
using __gnu_cxx::hash; typedef unordered_multimap<__K,__T,__H,__E,__A> _super;
# endif typedef __T data_type;
using __gnu_cxx::hash_map;
using __gnu_cxx::hash_multimap; hash_multimap( void) {}
} hash_multimap( size_t n) : _super( n) {}
#else #ifdef BOOST_TR1_UNORDERED_MAP_INCLUDED // workaround pre-BOOST_UNORDERED_USE_MOVE problem
# error UNSUPPORTED COMPILER // in derived classes the copy assignment operator can only be declared implicitly if
// its base class's assignment operator has the canonical signature.
// boost's assignment operators don't have this canonical signature when move-semantics are enabled
hash_multimap& operator=( const hash_multimap& r) { hash_multimap c(r); this->swap(c); return *this; }
#endif #endif
void resize( size_t n) { _super::rehash(n); }
private:
// setting the hasher dynamically is not supported in the emulation!
hash_multimap( size_t, const __H&, const __E& rE=__E(), const __A& rA=__A()); // not implemented
};
} // namespace std
#endif // NO_STLPORT4_EMULATION
#endif #endif
/* vi:set tabstop=4 shiftwidth=4 expandtab: */
...@@ -22,25 +22,85 @@ ...@@ -22,25 +22,85 @@
#ifndef SYSTEM_STL_HASHSET #ifndef SYSTEM_STL_HASHSET
#define SYSTEM_STL_HASHSET #define SYSTEM_STL_HASHSET
#ifdef GCC #ifdef HAVE_STL_INCLUDE_PATH
// TODO: use computed include file name
#include_next <unordered_set>
#elif defined(_MSC_VER)
#include <../../VC/include/unordered_set>
#define STLP4_EMUBASE_NS ::std::tr1
#else // fall back to boost/tr1
#include <boost/tr1/tr1/unordered_set>
#define STLP4_EMUBASE_NS ::boost
#endif
# include <functional>
# define _BACKWARD_BACKWARD_WARNING_H 1 #ifndef NO_STLPORT4_EMULATION
# include <ext/hash_set>
# undef _BACKWARD_BACKWARD_WARNING_H
namespace std namespace std
{ {
# ifndef __GXX_EXPERIMENTAL_CXX0X__ #ifdef STLP4_EMUBASE_NS
using __gnu_cxx::hash; using STLP4_EMUBASE_NS::hash;
# endif using STLP4_EMUBASE_NS::unordered_set;
using __gnu_cxx::hash_set; using STLP4_EMUBASE_NS::unordered_multiset;
using __gnu_cxx::hash_multiset; #undef STLP4_EMUBASE_NS
}
#else
# error UNSUPPORTED COMPILER
#endif #endif
template<
typename __K,
typename __H = hash<__K>,
typename __E = equal_to<__K>,
typename __A = allocator<__K> >
class hash_set
: public unordered_set<__K,__H,__E,__A>
{
typedef unordered_set<__K,__H,__E,__A> _super;
public:
hash_set( void) {}
hash_set( size_t n) : _super(n) {}
void resize( size_t n) { _super::rehash( n); }
#ifdef BOOST_TR1_UNORDERED_SET_INCLUDED // workaround pre-BOOST_UNORDERED_USE_MOVE problem
// in derived classes the copy assignment operator can only be declared implicitly if
// its base class's assignment operator has the canonical signature.
// boost's assignment operators don't have this canonical signature when move-semantics are enabled
hash_set& operator=( const hash_set& r) { hash_set c(r); this->swap(c); return *this; }
#endif #endif
/* vi:set tabstop=4 shiftwidth=4 expandtab: */
private:
// setting the hasher dynamically is not supported in the emulation!
hash_set( size_t, const __H&, const __E& rE=__E(), const __A& rA=__A()); // not implemented
};
template<
typename __K,
typename __H = hash<__K>,
typename __E = equal_to<__K>,
typename __A = allocator<__K> >
class hash_multiset
: public unordered_multiset<__K,__H,__E,__A>
{
typedef unordered_multiset<__K,__H,__E,__A> _super;
public:
hash_multiset( void) {}
hash_multiset( size_t n) : _super( n) {}
void resize( size_t n) { _super::rehash( n); }
#ifdef BOOST_TR1_UNORDERED_SET_INCLUDED // workaround pre-BOOST_UNORDERED_USE_MOVE problem
// in derived classes the copy assignment operator can only be declared implicitly if
// its base class's assignment operator has the canonical signature.
// boost's assignment operators don't have this canonical signature when move-semantics are enabled
hash_multiset& operator=( const hash_multiset& r) { hash_multiset c(r); this->swap(c); return *this; }
#endif
private:
// setting the hasher dynamically is not supported in the emulation!
hash_multiset( size_t, const __H&, const __E& rE=__E(), const __A& rA=__A()); // not implemented
};
} // namespace std
#endif // NO_STLPORT4_EMULATION
#endif
...@@ -22,26 +22,14 @@ ...@@ -22,26 +22,14 @@
#ifndef SYSTEM_STL_NUMERIC #ifndef SYSTEM_STL_NUMERIC
#define SYSTEM_STL_NUMERIC #define SYSTEM_STL_NUMERIC
#ifdef GCC #ifdef HAVE_STL_INCLUDE_PATH
# include <functional> // TODO: use computed include file name
# ifdef __MINGW32__ #include_next <numeric>
# define _SYSTEM_STL_MAKE_HEADER(path,header) <path/header> #elif defined(_MSC_VER)
# include _SYSTEM_STL_MAKE_HEADER(GXX_INCLUDE_PATH,numeric) #include <../../VC/include/numeric>
# else #else // fall back to boost/tr1
# include <ext/../numeric> #include <boost/tr1/tr1/numeric>
# endif
# include <ext/numeric>
# ifndef __GXX_EXPERIMENTAL_CXX0X__
namespace std
{
using __gnu_cxx::iota;
}
# endif
#else
# error UNSUPPORTED COMPILER
#endif #endif
#endif #endif
/* vi:set tabstop=4 shiftwidth=4 expandtab: */
...@@ -22,18 +22,54 @@ ...@@ -22,18 +22,54 @@
#ifndef SYSTEM_STL_SLIST #ifndef SYSTEM_STL_SLIST
#define SYSTEM_STL_SLIST #define SYSTEM_STL_SLIST
#ifdef GCC #ifdef HAVE_STL_INCLUDE_PATH
// TODO: use computed include file name
#include_next <forward_list>
#elif defined(_MSC_VER)
#include <../../VC/include/list>
#define STLP4_SLIST_WITH_LIST
// MSVC's list would cause a lot of expression-result-unused warnings
// unless it is compiled in iterator-debugging mode. Silence this noise
#pragma warning(disable:4555)
#else // fall back to boost/tr1 (forward_list or plain list)
#include <boost/config.hpp>
#ifndef BOOST_NO_0X_HDR_FORWARD_LIST
#include <boost/tr1/tr1/forward_list>
#else // fall back to the classic list
#include <boost/tr1/tr1/list>
#define STLP4_SLIST_WITH_LIST
#endif
#endif
#ifndef NO_STLPORT4_EMULATION
#include <ext/slist> #ifndef STLP4_SLIST_WITH_LIST
#define STLP4_SLIST_EMUBASE std::forward_list
#else
#define STLP4_SLIST_EMUBASE std::list
#endif
namespace std namespace std
{ {
using __gnu_cxx::slist; using STLP4_SLIST_EMUBASE;
}
#else // lame emulation of the pre-C++11 slist using the std::forward_list (or std::list)
#error UNSUPPORTED COMPILER template< typename T, class A=allocator<T> >
class slist : public STLP4_SLIST_EMUBASE<T,A>
{
public:
typedef typename STLP4_SLIST_EMUBASE<T,A> _super;
typedef typename _super::iterator slist_mit;
typedef typename _super::const_iterator slist_cit;
#ifndef STLP4_SLIST_WITH_LIST
slist_mit insert( slist_cit aI, const T& rT) { return _super::insert_after( aI, rT); }
#endif #endif
};
}
#endif // NO_STLPORT4_EMULATION
#endif #endif
/* vi:set tabstop=4 shiftwidth=4 expandtab: */
...@@ -22,22 +22,38 @@ ...@@ -22,22 +22,38 @@
#ifndef SYSTEM_STL_VECTOR #ifndef SYSTEM_STL_VECTOR
#define SYSTEM_STL_VECTOR #define SYSTEM_STL_VECTOR
#ifdef GCC #ifdef HAVE_STL_INCLUDE_PATH
// TODO: use computed include file name
#ifdef __MINGW32__ #include_next <vector>
# define _SYSTEM_STL_MAKE_HEADER(path,header) <path/header> #elif defined(_MSC_VER)
# include _SYSTEM_STL_MAKE_HEADER(GXX_INCLUDE_PATH,vector) #include <../../VC/include/vector>
#else #else // fall back to boost/tr1
# include <ext/../vector> #include <boost/tr1/tr1/vector>
#endif #endif
#ifndef NO_STLPORT4_EMULATION
namespace std namespace std
{ {
typedef vector<bool, std::allocator<bool> > bit_vector; typedef vector<bool> bit_vector;
} }
// workaround some STL implementations having problems with their vector<bool>::count() specialization
inline int std_bitset_count( std::bit_vector::const_iterator it, std::bit_vector::const_iterator itEnd, bool bValue)
{
#if 0 && defined(_LIBCPP___BIT_REFERENCE) // TODO: reenable for libc++ >= r156543/r156546/etc.
int nCount = std::count( it, itEnd, bValue);
#else #else
#error UNSUPPORTED COMPILER int nCount = 0;
for(; it != itEnd; ++it)
if( *it == bValue)
++nCount;
#endif #endif
return nCount;
}
#endif // NO_STLPORT4_EMULATION
#endif #endif
/* vi:set tabstop=4 shiftwidth=4 expandtab: */
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