Use std::unordered_map instead of hash_map where available.

This commit is contained in:
Stephen Kelly 2015-05-16 06:57:53 +02:00
parent 820777af03
commit d7923b82ad
9 changed files with 85 additions and 5 deletions

View File

@ -48,6 +48,7 @@ if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
endif()
include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx11_unordered_map.cmake)
# option to set the internal encoding of CMake to UTF-8
option(CMAKE_ENCODING_UTF8 "Use UTF-8 encoding internally." ON)

View File

@ -0,0 +1,25 @@
if(CMAKE_CXX_STANDARD AND NOT DEFINED CMake_HAVE_CXX11_UNORDERED_MAP)
message(STATUS "Checking if compiler supports C++11 unordered_map")
try_compile(CMake_HAVE_CXX11_UNORDERED_MAP
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_LIST_DIR}/cm_cxx11_unordered_map.cpp
CMAKE_FLAGS -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
OUTPUT_VARIABLE OUTPUT
)
if(CMake_HAVE_CXX11_UNORDERED_MAP)
message(STATUS "Checking if compiler supports C++11 unordered_map - yes")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if compiler supports C++11 unordered_map passed with the following output:\n"
"${OUTPUT}\n"
"\n"
)
else()
message(STATUS "Checking if compiler supports C++11 unordered_map - no")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if compiler supports C++11 unordered_map failed with the following output:\n"
"${OUTPUT}\n"
"\n"
)
endif()
endif()

View File

@ -0,0 +1,6 @@
#include <unordered_map>
int main() {
std::unordered_map<int, int> map;
map[0] = 0;
return 0;
}

View File

@ -14,4 +14,5 @@
#cmakedefine CMAKE_USE_ELF_PARSER
#cmakedefine CMAKE_USE_MACH_PARSER
#cmakedefine CMAKE_ENCODING_UTF8
#cmakedefine CMake_HAVE_CXX11_UNORDERED_MAP
#define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@"

View File

@ -14,8 +14,12 @@
#include "cmStandardIncludes.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
#include <unordered_map>
#else
#include "cmsys/hash_map.hxx"
#endif
#endif
#include <list>
@ -65,9 +69,12 @@ private:
};
static Def NoDef;
// Local definitions, set or unset.
#if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string, Def> MapType;
#else
typedef cmsys::hash_map<std::string, Def> MapType;
#endif
#else
typedef std::map<std::string, Def> MapType;
#endif

View File

@ -13,8 +13,12 @@
// Use a hash table to avoid duplicate file time checks from disk.
#if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
#include <unordered_map>
#else
# include <cmsys/hash_map.hxx>
#endif
#endif
#include <cmsys/Encoding.hxx>
@ -47,9 +51,17 @@ private:
{
return h(s.c_str());
}
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
std::hash<const char*> h;
#else
cmsys::hash<const char*> h;
#endif
};
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string,
#else
typedef cmsys::hash_map<std::string,
#endif
cmFileTimeComparison_Type, HashString> FileStatsMap;
FileStatsMap Files;
#endif

View File

@ -24,7 +24,11 @@
#if defined(CMAKE_BUILD_WITH_CMAKE)
# include "cmFileLockPool.h"
# include <cmsys/hash_map.hxx>
# ifdef CMake_HAVE_CXX11_UNORDERED_MAP
# include <unordered_map>
# else
# include <cmsys/hash_map.hxx>
# endif
#endif
class cmake;
@ -429,7 +433,11 @@ protected:
// All targets in the entire project.
#if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string, cmTarget*> TargetMap;
#else
typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
#endif
#else
typedef std::map<std::string,cmTarget *> TargetMap;
#endif

View File

@ -31,7 +31,11 @@
#include <cmsys/auto_ptr.hxx>
#include <cmsys/RegularExpression.hxx>
#if defined(CMAKE_BUILD_WITH_CMAKE)
# include <cmsys/hash_map.hxx>
# ifdef CMake_HAVE_CXX11_UNORDERED_MAP
# include <unordered_map>
# else
# include <cmsys/hash_map.hxx>
# endif
#endif
#include <stack>
@ -868,7 +872,11 @@ protected:
// libraries, classes, and executables
mutable cmTargets Targets;
#if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string, cmTarget*> TargetMap;
#else
typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
#endif
#else
typedef std::map<std::string, cmTarget*> TargetMap;
#endif
@ -1041,7 +1049,11 @@ private:
// A map for fast output to input look up.
#if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string, cmSourceFile*> OutputToSourceMap;
#else
typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap;
#endif
#else
typedef std::map<std::string, cmSourceFile*> OutputToSourceMap;
#endif

View File

@ -19,7 +19,11 @@
#include <cmsys/auto_ptr.hxx>
#if defined(CMAKE_BUILD_WITH_CMAKE)
#include <cmsys/hash_map.hxx>
# ifdef CMake_HAVE_CXX11_UNORDERED_MAP
# include <unordered_map>
# else
# include <cmsys/hash_map.hxx>
# endif
#endif
#define CM_FOR_EACH_TARGET_POLICY(F) \
@ -849,7 +853,11 @@ private:
};
#ifdef CMAKE_BUILD_WITH_CMAKE
typedef cmsys::hash_map<std::string,cmTarget> cmTargets;
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string, cmTarget> cmTargets;
#else
typedef cmsys::hash_map<std::string, cmTarget> cmTargets;
#endif
#else
typedef std::map<std::string,cmTarget> cmTargets;
#endif