From 86348a9d288e94f47447a760ce79675af6a3a57a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 11 Oct 2022 00:22:40 +0200 Subject: [PATCH] Stop testing for pre-standard hash map/set classes Always use std::unordered_{map,set} when we use them at all, don't bother with checking for their availability and with tr1 or even older alternatives. --- build/cmake/setup.cmake | 32 ------------------ build/cmake/setup.h.in | 37 --------------------- configure | 4 --- configure.in | 3 -- include/wx/defs.h | 7 ---- include/wx/hashmap.h | 61 +++++++---------------------------- include/wx/hashset.h | 57 ++++++-------------------------- include/wx/osx/config_xcode.h | 4 --- setup.h.in | 37 --------------------- setup.h_vms | 37 --------------------- 10 files changed, 21 insertions(+), 258 deletions(-) diff --git a/build/cmake/setup.cmake b/build/cmake/setup.cmake index 2386a2eefe..98b8259762 100644 --- a/build/cmake/setup.cmake +++ b/build/cmake/setup.cmake @@ -132,38 +132,6 @@ if(NOT MSVC) endif() endif() -wx_check_cxx_source_compiles(" - std::hash_map, std::equal_to > test1; - std::hash_set, std::equal_to > test2;" - HAVE_HASH_MAP - hash_map hash_set - ) -set(HAVE_STD_HASH_MAP ${HAVE_HASH_MAP}) - -wx_check_cxx_source_compiles(" - __gnu_cxx::hash_map, std::equal_to > test1; - __gnu_cxx::hash_set, std::equal_to > test2;" - HAVE_EXT_HASH_MAP - ext/hash_map ext/hash_set - ) -set(HAVE_GNU_CXX_HASH_MAP ${HAVE_EXT_HASH_MAP}) - -wx_check_cxx_source_compiles(" - std::unordered_map test1; - std::unordered_set test2;" - HAVE_STD_UNORDERED_MAP - unordered_map unordered_set - ) -set(HAVE_STD_UNORDERED_SET ${HAVE_STD_UNORDERED_MAP}) - -wx_check_cxx_source_compiles(" - std::tr1::unordered_map test1; - std::tr1::unordered_set test2;" - HAVE_TR1_UNORDERED_MAP - tr1/unordered_map tr1/unordered_set - ) -set(HAVE_TR1_UNORDERED_SET ${HAVE_TR1_UNORDERED_MAP}) - # Check for availability of GCC's atomic operations builtins. wx_check_c_source_compiles(" unsigned int value=0; diff --git a/build/cmake/setup.h.in b/build/cmake/setup.h.in index 89ab30f698..a1ab322b6f 100644 --- a/build/cmake/setup.h.in +++ b/build/cmake/setup.h.in @@ -741,43 +741,6 @@ */ #cmakedefine VA_LIST_IS_ARRAY 1 -/* - * Define if your compiler has - */ -#cmakedefine HAVE_HASH_MAP 1 -/* - * Define if your compiler has - */ -#cmakedefine HAVE_EXT_HASH_MAP 1 -/* - * Define if your compiler has std::hash_map/hash_set - */ -#cmakedefine HAVE_STD_HASH_MAP 1 -/* - * Define if your compiler has __gnu_cxx::hash_map/hash_set - */ -#cmakedefine HAVE_GNU_CXX_HASH_MAP 1 - -/* - * Define if your compiler has std::unordered_map - */ -#cmakedefine HAVE_STD_UNORDERED_MAP 1 - -/* - * Define if your compiler has std::unordered_set - */ -#cmakedefine HAVE_STD_UNORDERED_SET 1 - -/* - * Define if your compiler has std::tr1::unordered_map - */ -#cmakedefine HAVE_TR1_UNORDERED_MAP 1 - -/* - * Define if your compiler has std::tr1::unordered_set - */ -#cmakedefine HAVE_TR1_UNORDERED_SET 1 - /* * Define if the compiler supports simple visibility declarations. */ diff --git a/configure b/configure index 88b1210706..0069e1538a 100755 --- a/configure +++ b/configure @@ -24728,10 +24728,6 @@ if test "x$COMPAQCXX" = "xyes"; then CXXFLAGS="-w0 -msg_disable basclsnondto,unrimpret,intconlosbit" fi -$as_echo "#define HAVE_STD_UNORDERED_MAP 1" >>confdefs.h - -$as_echo "#define HAVE_STD_UNORDERED_SET 1" >>confdefs.h - diff --git a/configure.in b/configure.in index d464779f8b..6fedf2c52d 100644 --- a/configure.in +++ b/configure.in @@ -1880,9 +1880,6 @@ if test "x$COMPAQCXX" = "xyes"; then CXXFLAGS="-w0 -msg_disable basclsnondto,unrimpret,intconlosbit" fi -AC_DEFINE(HAVE_STD_UNORDERED_MAP) -AC_DEFINE(HAVE_STD_UNORDERED_SET) - dnl check for atomic operations builtins for wx/atomic.h: WX_ATOMIC_BUILTINS diff --git a/include/wx/defs.h b/include/wx/defs.h index 568989ffb9..e32f16c006 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -315,13 +315,6 @@ typedef short int WXTYPE; /* for consistency with wxStatic/DynamicCast defined in wx/object.h */ #define wxConstCast(obj, className) const_cast(obj) -#ifndef HAVE_STD_UNORDERED_MAP - #define HAVE_STD_UNORDERED_MAP -#endif -#ifndef HAVE_STD_UNORDERED_SET - #define HAVE_STD_UNORDERED_SET -#endif - #endif /* __cplusplus */ /* provide replacement for C99 va_copy() if the compiler doesn't have it */ diff --git a/include/wx/hashmap.h b/include/wx/hashmap.h index e4d0f5a3a7..1c09d722b6 100644 --- a/include/wx/hashmap.h +++ b/include/wx/hashmap.h @@ -14,51 +14,14 @@ #include "wx/string.h" #include "wx/wxcrt.h" -// In wxUSE_STD_CONTAINERS build we prefer to use the standard hash map class -// but it can be either in non-standard hash_map header (old g++ and some other -// STL implementations) or in C++0x standard unordered_map which can in turn be -// available either in std::tr1 or std namespace itself -// -// To summarize: if std::unordered_map is available use it, otherwise use tr1 -// and finally fall back to non-standard hash_map +#if wxUSE_STD_CONTAINERS -#if (defined(HAVE_EXT_HASH_MAP) || defined(HAVE_HASH_MAP)) \ - && (defined(HAVE_GNU_CXX_HASH_MAP) || defined(HAVE_STD_HASH_MAP)) - #define HAVE_STL_HASH_MAP -#endif - -#if wxUSE_STD_CONTAINERS && \ - (defined(HAVE_STD_UNORDERED_MAP) || defined(HAVE_TR1_UNORDERED_MAP)) - -#if defined(HAVE_STD_UNORDERED_MAP) - #include - #define WX_HASH_MAP_NAMESPACE std -#elif defined(HAVE_TR1_UNORDERED_MAP) - #include - #define WX_HASH_MAP_NAMESPACE std::tr1 -#endif +#include #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \ - typedef WX_HASH_MAP_NAMESPACE::unordered_map< KEY_T, VALUE_T, HASH_T, KEY_EQ_T > CLASSNAME + typedef std::unordered_map< KEY_T, VALUE_T, HASH_T, KEY_EQ_T > CLASSNAME -#elif wxUSE_STD_CONTAINERS && defined(HAVE_STL_HASH_MAP) - -#if defined(HAVE_EXT_HASH_MAP) - #include -#elif defined(HAVE_HASH_MAP) - #include -#endif - -#if defined(HAVE_GNU_CXX_HASH_MAP) - #define WX_HASH_MAP_NAMESPACE __gnu_cxx -#elif defined(HAVE_STD_HASH_MAP) - #define WX_HASH_MAP_NAMESPACE std -#endif - -#define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \ - typedef WX_HASH_MAP_NAMESPACE::hash_map< KEY_T, VALUE_T, HASH_T, KEY_EQ_T > CLASSNAME - -#else // !wxUSE_STD_CONTAINERS || no std::{hash,unordered}_map class available +#else // !wxUSE_STD_CONTAINERS #define wxNEEDS_WX_HASH_MAP @@ -472,12 +435,12 @@ inline bool grow_lf70( size_t buckets, size_t items ) struct WXDLLIMPEXP_BASE wxIntegerHash { private: - WX_HASH_MAP_NAMESPACE::hash longHash; - WX_HASH_MAP_NAMESPACE::hash ulongHash; - WX_HASH_MAP_NAMESPACE::hash intHash; - WX_HASH_MAP_NAMESPACE::hash uintHash; - WX_HASH_MAP_NAMESPACE::hash shortHash; - WX_HASH_MAP_NAMESPACE::hash ushortHash; + std::hash longHash; + std::hash ulongHash; + std::hash intHash; + std::hash uintHash; + std::hash shortHash; + std::hash ushortHash; #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG // hash ought to work but doesn't on some compilers @@ -489,9 +452,9 @@ private: longHash( wx_truncate_cast(long, x >> (sizeof(long) * 8)) ); } #elif defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG - WX_HASH_MAP_NAMESPACE::hash longlongHash; + std::hash longlongHash; #else - WX_HASH_MAP_NAMESPACE::hash longlongHash; + std::hash longlongHash; #endif #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG diff --git a/include/wx/hashset.h b/include/wx/hashset.h index 311aeca9a6..5c92aa3cf0 100644 --- a/include/wx/hashset.h +++ b/include/wx/hashset.h @@ -16,79 +16,40 @@ // see comment in wx/hashmap.h which also applies to different standard hash // set classes -#if wxUSE_STD_CONTAINERS && \ - (defined(HAVE_STD_UNORDERED_SET) || defined(HAVE_TR1_UNORDERED_SET)) +#if wxUSE_STD_CONTAINERS -#if defined(HAVE_STD_UNORDERED_SET) - #include - #define WX_HASH_SET_BASE_TEMPLATE std::unordered_set -#elif defined(HAVE_TR1_UNORDERED_SET) - #include - #define WX_HASH_SET_BASE_TEMPLATE std::tr1::unordered_set -#else - #error Update this code: unordered_set is available, but I do not know where. -#endif - -#elif wxUSE_STD_CONTAINERS && defined(HAVE_STL_HASH_MAP) - -#if defined(HAVE_EXT_HASH_MAP) - #include -#elif defined(HAVE_HASH_MAP) - #include -#endif - -#define WX_HASH_SET_BASE_TEMPLATE WX_HASH_MAP_NAMESPACE::hash_set - -#endif // different hash_set/unordered_set possibilities - -#ifdef WX_HASH_SET_BASE_TEMPLATE +#include // we need to define the class declared by _WX_DECLARE_HASH_SET as a class and // not a typedef to allow forward declaring it #define _WX_DECLARE_HASH_SET_IMPL( KEY_T, HASH_T, KEY_EQ_T, PTROP, CLASSNAME, CLASSEXP ) \ CLASSEXP CLASSNAME \ - : public WX_HASH_SET_BASE_TEMPLATE< KEY_T, HASH_T, KEY_EQ_T > \ + : public std::unordered_set< KEY_T, HASH_T, KEY_EQ_T > \ { \ public: \ explicit CLASSNAME(size_type n = 3, \ const hasher& h = hasher(), \ const key_equal& ke = key_equal(), \ const allocator_type& a = allocator_type()) \ - : WX_HASH_SET_BASE_TEMPLATE< KEY_T, HASH_T, KEY_EQ_T >(n, h, ke, a) \ + : std::unordered_set< KEY_T, HASH_T, KEY_EQ_T >(n, h, ke, a) \ {} \ template \ CLASSNAME(InputIterator f, InputIterator l, \ const hasher& h = hasher(), \ const key_equal& ke = key_equal(), \ const allocator_type& a = allocator_type()) \ - : WX_HASH_SET_BASE_TEMPLATE< KEY_T, HASH_T, KEY_EQ_T >(f, l, h, ke, a)\ + : std::unordered_set< KEY_T, HASH_T, KEY_EQ_T >(f, l, h, ke, a) \ {} \ - CLASSNAME(const WX_HASH_SET_BASE_TEMPLATE< KEY_T, HASH_T, KEY_EQ_T >& s) \ - : WX_HASH_SET_BASE_TEMPLATE< KEY_T, HASH_T, KEY_EQ_T >(s) \ + CLASSNAME(const std::unordered_set< KEY_T, HASH_T, KEY_EQ_T >& s) \ + : std::unordered_set< KEY_T, HASH_T, KEY_EQ_T >(s) \ {} \ } -// In some standard library implementations (in particular, the libstdc++ that -// ships with g++ 4.7), std::unordered_set inherits privately from its hasher -// and comparator template arguments for purposes of empty base optimization. -// As a result, in the declaration of a class deriving from std::unordered_set -// the names of the hasher and comparator classes are interpreted as naming -// the base class which is inaccessible. -// The workaround is to prefix the class names with 'struct'; however, don't -// do this unconditionally, as with other compilers (both MSVC and clang) -// doing it causes a warning if the class was declared as a 'class' rather than -// a 'struct'. -#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 7) -#define WX_MAYBE_PREFIX_WITH_STRUCT(STRUCTNAME) struct STRUCTNAME -#else -#define WX_MAYBE_PREFIX_WITH_STRUCT(STRUCTNAME) STRUCTNAME -#endif - #define _WX_DECLARE_HASH_SET( KEY_T, HASH_T, KEY_EQ_T, PTROP, CLASSNAME, CLASSEXP ) \ _WX_DECLARE_HASH_SET_IMPL( \ KEY_T, \ - WX_MAYBE_PREFIX_WITH_STRUCT(HASH_T), \ - WX_MAYBE_PREFIX_WITH_STRUCT(KEY_EQ_T), \ + HASH_T, \ + KEY_EQ_T, \ PTROP, \ CLASSNAME, \ CLASSEXP) diff --git a/include/wx/osx/config_xcode.h b/include/wx/osx/config_xcode.h index 5692f5cada..fbf6e4b3c7 100644 --- a/include/wx/osx/config_xcode.h +++ b/include/wx/osx/config_xcode.h @@ -23,10 +23,6 @@ #define HAVE_VA_COPY 1 #if __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 2 ) - #if !defined(__has_include) - #define HAVE_TR1_UNORDERED_MAP 1 - #define HAVE_TR1_UNORDERED_SET 1 - #endif #define HAVE_GCC_ATOMIC_BUILTINS 1 #endif #define HAVE_VISIBILITY 1 diff --git a/setup.h.in b/setup.h.in index d6094b4a27..de7a4ffb83 100644 --- a/setup.h.in +++ b/setup.h.in @@ -741,43 +741,6 @@ */ #undef VA_LIST_IS_ARRAY -/* - * Define if your compiler has - */ -#undef HAVE_HASH_MAP -/* - * Define if your compiler has - */ -#undef HAVE_EXT_HASH_MAP -/* - * Define if your compiler has std::hash_map/hash_set - */ -#undef HAVE_STD_HASH_MAP -/* - * Define if your compiler has __gnu_cxx::hash_map/hash_set - */ -#undef HAVE_GNU_CXX_HASH_MAP - -/* - * Define if your compiler has std::unordered_map - */ -#undef HAVE_STD_UNORDERED_MAP - -/* - * Define if your compiler has std::unordered_set - */ -#undef HAVE_STD_UNORDERED_SET - -/* - * Define if your compiler has std::tr1::unordered_map - */ -#undef HAVE_TR1_UNORDERED_MAP - -/* - * Define if your compiler has std::tr1::unordered_set - */ -#undef HAVE_TR1_UNORDERED_SET - /* * Define if the compiler supports simple visibility declarations. */ diff --git a/setup.h_vms b/setup.h_vms index 3ff59d6fcf..9a7e807c1d 100644 --- a/setup.h_vms +++ b/setup.h_vms @@ -807,43 +807,6 @@ typedef pid_t GPid; */ #undef VA_LIST_IS_ARRAY -/* - * Define if your compiler has - */ -#undef HAVE_HASH_MAP -/* - * Define if your compiler has - */ -#undef HAVE_EXT_HASH_MAP -/* - * Define if your compiler has std::hash_map/hash_set - */ -#undef HAVE_STD_HASH_MAP -/* - * Define if your compiler has __gnu_cxx::hash_map/hash_set - */ -#undef HAVE_GNU_CXX_HASH_MAP - -/* - * Define if your compiler has std::unordered_map - */ -#undef HAVE_STD_UNORDERED_MAP - -/* - * Define if your compiler has std::unordered_set - */ -#undef HAVE_STD_UNORDERED_SET - -/* - * Define if your compiler has std::tr1::unordered_map - */ -#undef HAVE_TR1_UNORDERED_MAP - -/* - * Define if your compiler has std::tr1::unordered_set - */ -#undef HAVE_TR1_UNORDERED_SET - /* * Define if the compiler supports simple visibility declarations. */