Use C++11 unordered containers

This commit is contained in:
Daniel Pfeifer
2017-08-22 23:05:27 +02:00
parent 8a0ed37f61
commit cbcfb79f9c
20 changed files with 45 additions and 131 deletions

View File

@@ -54,5 +54,3 @@ endif()
cm_check_cxx_feature(nullptr)
cm_check_cxx_feature(override)
cm_check_cxx_feature(unique_ptr)
cm_check_cxx_feature(unordered_map)
cm_check_cxx_feature(unordered_set)

View File

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

View File

@@ -1,7 +0,0 @@
#include <unordered_set>
int main()
{
std::unordered_set<int> set;
set.insert(0);
return 0;
}

View File

@@ -28,8 +28,6 @@
#cmakedefine CMake_HAVE_CXX_NULLPTR
#cmakedefine CMake_HAVE_CXX_OVERRIDE
#cmakedefine CMake_HAVE_CXX_UNIQUE_PTR
#cmakedefine CMake_HAVE_CXX_UNORDERED_MAP
#cmakedefine CMake_HAVE_CXX_UNORDERED_SET
#define CMAKE_BIN_DIR "/@CMAKE_BIN_DIR@"
#define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@"

View File

@@ -6,10 +6,10 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <unordered_map>
#include <vector>
#include "cmLinkedTree.h"
#include "cm_unordered_map.hxx"
/** \class cmDefinitions
* \brief Store a scope of variable definitions for CMake language.
@@ -70,7 +70,7 @@ private:
};
static Def NoDef;
typedef CM_UNORDERED_MAP<std::string, Def> MapType;
typedef std::unordered_map<std::string, Def> MapType;
MapType Map;
static Def const& GetInternal(const std::string& key, StackIter begin,

View File

@@ -4,6 +4,7 @@
#include "cmsys/FStream.hxx"
#include <map>
#include <unordered_map>
#include <utility>
#include "cmGeneratedFileStream.h"
@@ -14,7 +15,6 @@
#include "cmTarget.h"
#include "cmTargetLinkLibraryType.h"
#include "cm_auto_ptr.hxx"
#include "cm_unordered_map.hxx"
#include "cmake.h"
class cmExecutionStatus;

View File

@@ -4,10 +4,9 @@
#include <string>
#include <time.h>
#include <unordered_map>
#include <utility>
#include "cm_unordered_map.hxx"
// Use a platform-specific API to get file times efficiently.
#if !defined(_WIN32) || defined(__CYGWIN__)
#include "cm_sys_stat.h"
@@ -27,7 +26,7 @@ public:
bool FileTimesDiffer(const char* f1, const char* f2);
private:
typedef CM_UNORDERED_MAP<std::string, cmFileTimeComparison_Type>
typedef std::unordered_map<std::string, cmFileTimeComparison_Type>
FileStatsMap;
FileStatsMap Files;

View File

@@ -12,6 +12,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_set>
#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
@@ -32,7 +33,6 @@
#include "cmTargetLinkLibraryType.h"
#include "cmTargetPropertyComputer.h"
#include "cm_auto_ptr.hxx"
#include "cm_unordered_set.hxx"
#include "cmake.h"
class cmMessenger;
@@ -823,7 +823,7 @@ static void AddInterfaceEntries(
static bool processSources(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& srcs, CM_UNORDERED_SET<std::string>& uniqueSrcs,
std::vector<std::string>& srcs, std::unordered_set<std::string>& uniqueSrcs,
cmGeneratorExpressionDAGChecker* dagChecker, std::string const& config,
bool debugSources)
{
@@ -950,7 +950,7 @@ void cmGeneratorTarget::GetSourceFiles(std::vector<std::string>& files,
cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), "SOURCES",
CM_NULLPTR, CM_NULLPTR);
CM_UNORDERED_SET<std::string> uniqueSrcs;
std::unordered_set<std::string> uniqueSrcs;
bool contextDependentDirectSources =
processSources(this, this->SourceEntries, files, uniqueSrcs, &dagChecker,
config, debugSources);
@@ -1728,7 +1728,7 @@ class cmTargetCollectLinkLanguages
public:
cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
const std::string& config,
CM_UNORDERED_SET<std::string>& languages,
std::unordered_set<std::string>& languages,
cmGeneratorTarget const* head)
: Config(config)
, Languages(languages)
@@ -1795,7 +1795,7 @@ public:
private:
std::string Config;
CM_UNORDERED_SET<std::string>& Languages;
std::unordered_set<std::string>& Languages;
cmGeneratorTarget const* HeadTarget;
const cmGeneratorTarget* Target;
std::set<cmGeneratorTarget const*> Visited;
@@ -1867,7 +1867,7 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
LinkClosure& lc) const
{
// Get languages built in this target.
CM_UNORDERED_SET<std::string> languages;
std::unordered_set<std::string> languages;
cmLinkImplementation const* impl = this->GetLinkImplementation(config);
assert(impl);
for (std::vector<std::string>::const_iterator li = impl->Languages.begin();
@@ -1884,7 +1884,7 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
}
// Store the transitive closure of languages.
for (CM_UNORDERED_SET<std::string>::const_iterator li = languages.begin();
for (std::unordered_set<std::string>::const_iterator li = languages.begin();
li != languages.end(); ++li) {
lc.Languages.push_back(*li);
}
@@ -1905,7 +1905,8 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
}
// Now consider languages that propagate from linked targets.
for (CM_UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
for (std::unordered_set<std::string>::const_iterator sit =
languages.begin();
sit != languages.end(); ++sit) {
std::string propagates =
"CMAKE_" + *sit + "_LINKER_PREFERENCE_PROPAGATES";
@@ -2477,7 +2478,7 @@ static void processIncludeDirectories(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& includes,
CM_UNORDERED_SET<std::string>& uniqueIncludes,
std::unordered_set<std::string>& uniqueIncludes,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugIncludes, const std::string& language)
{
@@ -2591,7 +2592,7 @@ std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
const std::string& config, const std::string& lang) const
{
std::vector<std::string> includes;
CM_UNORDERED_SET<std::string> uniqueIncludes;
std::unordered_set<std::string> uniqueIncludes;
cmGeneratorExpressionDAGChecker dagChecker(
this->GetName(), "INCLUDE_DIRECTORIES", CM_NULLPTR, CM_NULLPTR);
@@ -2657,7 +2658,7 @@ static void processCompileOptionsInternal(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& options,
CM_UNORDERED_SET<std::string>& uniqueOptions,
std::unordered_set<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions, const char* logName, std::string const& language)
{
@@ -2695,7 +2696,7 @@ static void processCompileOptions(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& options,
CM_UNORDERED_SET<std::string>& uniqueOptions,
std::unordered_set<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions, std::string const& language)
{
@@ -2708,7 +2709,7 @@ void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
const std::string& config,
const std::string& language) const
{
CM_UNORDERED_SET<std::string> uniqueOptions;
std::unordered_set<std::string> uniqueOptions;
cmGeneratorExpressionDAGChecker dagChecker(
this->GetName(), "COMPILE_OPTIONS", CM_NULLPTR, CM_NULLPTR);
@@ -2749,7 +2750,7 @@ static void processCompileFeatures(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& options,
CM_UNORDERED_SET<std::string>& uniqueOptions,
std::unordered_set<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions)
{
@@ -2761,7 +2762,7 @@ static void processCompileFeatures(
void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
const std::string& config) const
{
CM_UNORDERED_SET<std::string> uniqueFeatures;
std::unordered_set<std::string> uniqueFeatures;
cmGeneratorExpressionDAGChecker dagChecker(
this->GetName(), "COMPILE_FEATURES", CM_NULLPTR, CM_NULLPTR);
@@ -2799,7 +2800,7 @@ static void processCompileDefinitions(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& options,
CM_UNORDERED_SET<std::string>& uniqueOptions,
std::unordered_set<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions, std::string const& language)
{
@@ -2812,7 +2813,7 @@ void cmGeneratorTarget::GetCompileDefinitions(
std::vector<std::string>& list, const std::string& config,
const std::string& language) const
{
CM_UNORDERED_SET<std::string> uniqueOptions;
std::unordered_set<std::string> uniqueOptions;
cmGeneratorExpressionDAGChecker dagChecker(
this->GetName(), "COMPILE_DEFINITIONS", CM_NULLPTR, CM_NULLPTR);
@@ -4363,7 +4364,7 @@ void cmGeneratorTarget::ComputeLinkInterface(
this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
// Shared libraries may have runtime implementation dependencies
// on other shared libraries that are not in the interface.
CM_UNORDERED_SET<std::string> emitted;
std::unordered_set<std::string> emitted;
for (std::vector<cmLinkItem>::const_iterator li =
iface.Libraries.begin();
li != iface.Libraries.end(); ++li) {

View File

@@ -9,6 +9,7 @@
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
@@ -19,7 +20,6 @@
#include "cmTarget.h"
#include "cmTargetDepend.h"
#include "cm_codecvt.hxx"
#include "cm_unordered_map.hxx"
#if defined(CMAKE_BUILD_WITH_CMAKE)
#include "cmFileLockPool.h"
@@ -488,9 +488,10 @@ protected:
const char* GetPredefinedTargetsFolder();
private:
typedef CM_UNORDERED_MAP<std::string, cmTarget*> TargetMap;
typedef CM_UNORDERED_MAP<std::string, cmGeneratorTarget*> GeneratorTargetMap;
typedef CM_UNORDERED_MAP<std::string, cmMakefile*> MakefileMap;
typedef std::unordered_map<std::string, cmTarget*> TargetMap;
typedef std::unordered_map<std::string, cmGeneratorTarget*>
GeneratorTargetMap;
typedef std::unordered_map<std::string, cmMakefile*> MakefileMap;
// Map efficiently from target name to cmTarget instance.
// Do not use this structure for looping over all targets.
// It contains both normal and globally visible imported targets.

View File

@@ -2,12 +2,12 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallTargetsCommand.h"
#include <unordered_map>
#include <utility>
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmTarget.h"
#include "cm_unordered_map.hxx"
class cmExecutionStatus;

View File

@@ -10,13 +10,13 @@
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "cmListFileCache.h"
#include "cmOutputConverter.h"
#include "cmPolicies.h"
#include "cmStateSnapshot.h"
#include "cm_unordered_map.hxx"
#include "cmake.h"
class cmComputeLinkInformation;
@@ -354,7 +354,8 @@ protected:
std::string::size_type ObjectPathMax;
std::set<std::string> ObjectMaxPathViolations;
typedef CM_UNORDERED_MAP<std::string, cmGeneratorTarget*> GeneratorTargetMap;
typedef std::unordered_map<std::string, cmGeneratorTarget*>
GeneratorTargetMap;
GeneratorTargetMap GeneratorTargetSearchIndex;
std::vector<cmGeneratorTarget*> GeneratorTargets;

View File

@@ -12,6 +12,7 @@
#include <stack>
#include <stddef.h>
#include <string>
#include <unordered_map>
#include <vector>
#include "cmAlgorithms.h"
@@ -22,7 +23,6 @@
#include "cmStateTypes.h"
#include "cmTarget.h"
#include "cm_auto_ptr.hxx"
#include "cm_unordered_map.hxx"
#include "cmake.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -871,7 +871,7 @@ private:
friend class cmParseFileScope;
std::vector<cmTarget*> ImportedTargetsOwned;
typedef CM_UNORDERED_MAP<std::string, cmTarget*> TargetMap;
typedef std::unordered_map<std::string, cmTarget*> TargetMap;
TargetMap ImportedTargets;
// Internal policy stack management.
@@ -909,7 +909,7 @@ private:
cmSourceFile* LinearGetSourceFileWithOutput(const std::string& cname) const;
// A map for fast output to input look up.
typedef CM_UNORDERED_MAP<std::string, cmSourceFile*> OutputToSourceMap;
typedef std::unordered_map<std::string, cmSourceFile*> OutputToSourceMap;
OutputToSourceMap OutputToSource;
void UpdateOutputToSourceMap(std::vector<std::string> const& outputs,

View File

@@ -5,6 +5,7 @@
#include "cmsys/FStream.hxx"
#include "cmsys/RegularExpression.hxx"
#include <map>
#include <unordered_map>
#include <utility>
#include "cmAlgorithms.h"
@@ -13,7 +14,6 @@
#include "cmSourceFile.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cm_unordered_map.hxx"
class cmExecutionStatus;

View File

@@ -9,6 +9,7 @@
#include <set>
#include <sstream>
#include <string.h>
#include <unordered_set>
#include "cmAlgorithms.h"
#include "cmGeneratorExpression.h"
@@ -26,7 +27,6 @@
#include "cmStateSnapshot.h"
#include "cmSystemTools.h"
#include "cmTargetPropertyComputer.h"
#include "cm_unordered_set.hxx"
#include "cmake.h"
template <>
@@ -1180,7 +1180,7 @@ const char* cmTarget::GetComputedProperty(
const char* cmTarget::GetProperty(const std::string& prop) const
{
static CM_UNORDERED_SET<std::string> specialProps;
static std::unordered_set<std::string> specialProps;
#define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
MAKE_STATIC_PROP(LINK_LIBRARIES);
MAKE_STATIC_PROP(TYPE);

View File

@@ -9,6 +9,7 @@
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
@@ -19,7 +20,6 @@
#include "cmPropertyMap.h"
#include "cmStateTypes.h"
#include "cmTargetLinkLibraryType.h"
#include "cm_unordered_map.hxx"
class cmGlobalGenerator;
class cmMakefile;
@@ -323,7 +323,7 @@ private:
cmListFileBacktrace Backtrace;
};
typedef CM_UNORDERED_MAP<std::string, cmTarget> cmTargets;
typedef std::unordered_map<std::string, cmTarget> cmTargets;
class cmTargetSet : public std::set<std::string>
{

View File

@@ -4,11 +4,11 @@
#include "cmTargetPropertyComputer.h"
#include <sstream>
#include <unordered_set>
#include "cmMessenger.h"
#include "cmPolicies.h"
#include "cmStateSnapshot.h"
#include "cm_unordered_set.hxx"
#include "cmake.h"
bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
@@ -49,7 +49,7 @@ bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
if (cmHasLiteralPrefix(prop, "INTERFACE_")) {
return true;
}
static CM_UNORDERED_SET<std::string> builtIns;
static std::unordered_set<std::string> builtIns;
if (builtIns.empty()) {
builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");

View File

@@ -1,25 +0,0 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef CM_UNORDERED_MAP_HXX
#define CM_UNORDERED_MAP_HXX
#include "cmConfigure.h"
#if defined(CMake_HAVE_CXX_UNORDERED_MAP)
#include <unordered_map>
#define CM_UNORDERED_MAP std::unordered_map
#elif defined(CMAKE_BUILD_WITH_CMAKE)
#include "cmsys/hash_map.hxx"
#define CM_UNORDERED_MAP cmsys::hash_map
#else
#include <map>
#define CM_UNORDERED_MAP std::map
#endif
#endif

View File

@@ -1,25 +0,0 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef CM_UNORDERED_SET_HXX
#define CM_UNORDERED_SET_HXX
#include "cmConfigure.h"
#if defined(CMake_HAVE_CXX_UNORDERED_SET)
#include <unordered_set>
#define CM_UNORDERED_SET std::unordered_set
#elif defined(CMAKE_BUILD_WITH_CMAKE)
#include "cmsys/hash_set.hxx"
#define CM_UNORDERED_SET cmsys::hash_set
#else
#include <set>
#define CM_UNORDERED_SET std::set
#endif
#endif

View File

@@ -32,7 +32,7 @@
#include "cmGraphVizWriter.h"
#include "cmVariableWatch.h"
#include "cm_unordered_map.hxx"
#include <unordered_map>
#endif
// only build kdevelop generator on non-windows platforms
@@ -120,7 +120,7 @@
namespace {
#if defined(CMAKE_BUILD_WITH_CMAKE)
typedef CM_UNORDERED_MAP<std::string, Json::Value> JsonValueMapType;
typedef std::unordered_map<std::string, Json::Value> JsonValueMapType;
#endif
} // namespace

View File

@@ -68,18 +68,6 @@
{ symbol: [ "std::__decay_and_strip<cmFindPackageCommand::PathLabel &>::__type", private, "\"cmConfigure.h\"", public ] },
{ symbol: [ "std::__decay_and_strip<__gnu_cxx::__normal_iterator<const cmCTestTestHandler::cmCTestTestProperties *, std::vector<cmCTestTestHandler::cmCTestTestProperties, std::allocator<cmCTestTestHandler::cmCTestTestProperties> > > &>::__type", private, "\"cmConfigure.h\"", public ] },
# Wrappers for headers added in TR1 / C++11
# { include: [ "<array>", public, "\"cm_array.hxx\"", public ] },
# { include: [ "<functional>", public, "\"cm_functional.hxx\"", public ] },
# { include: [ "<memory>", public, "\"cm_memory.hxx\"", public ] },
{ include: [ "<unordered_map>", public, "\"cm_unordered_map.hxx\"", public ] },
{ include: [ "<unordered_set>", public, "\"cm_unordered_set.hxx\"", public ] },
# { include: [ "<tr1/array>", public, "\"cm_array.hxx\"", public ] },
# { include: [ "<tr1/functional>", public, "\"cm_functional.hxx\"", public ] },
# { include: [ "<tr1/memory>", public, "\"cm_memory.hxx\"", public ] },
{ include: [ "<tr1/unordered_map>", public, "\"cm_unordered_map.hxx\"", public ] },
{ include: [ "<tr1/unordered_set>", public, "\"cm_unordered_set.hxx\"", public ] },
# KWIML
{ include: [ "<stdint.h>", public, "\"cm_kwiml.h\"", public ] },
{ include: [ "<inttypes.h>", public, "\"cm_kwiml.h\"", public ] },
@@ -88,14 +76,6 @@
{ include: [ "<sys/stat.h>", public, "\"cm_sys_stat.h\"", public ] },
{ symbol: [ "mode_t", private, "\"cm_sys_stat.h\"", public ] },
# TODO: remove once TR1 / C++11 is required.
{ include: [ "\"cmsys/hash_fun.hxx\"", private, "\"cm_unordered_map.hxx\"", public ] },
{ include: [ "\"cmsys/hash_fun.hxx\"", private, "\"cm_unordered_set.hxx\"", public ] },
{ include: [ "\"cmsys/hash_map.hxx\"", private, "\"cm_unordered_map.hxx\"", public ] },
{ include: [ "\"cmsys/hash_set.hxx\"", private, "\"cm_unordered_set.hxx\"", public ] },
{ include: [ "\"cmsys/hashtable.hxx\"", private, "\"cm_unordered_map.hxx\"", public ] },
{ include: [ "\"cmsys/hashtable.hxx\"", private, "\"cm_unordered_set.hxx\"", public ] },
# Wrappers for 3rd-party libraries used from the system.
{ include: [ "<archive.h>", private, "\"cm_libarchive.h\"", public ] },
{ include: [ "<archive_entry.h>", private, "\"cm_libarchive.h\"", public ] },