From f1dd0eeaaf264ebb35b048f423c66296e6967d16 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 24 Sep 2018 10:54:18 -0400 Subject: cmListFileCache: Add wrapper template for values with a backtrace --- Source/cmListFileCache.cxx | 7 ++++++- Source/cmListFileCache.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 4d7e1e2..d79afc6 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -9,10 +9,10 @@ #include "cmSystemTools.h" #include "cmake.h" -#include #include #include #include +#include cmCommandContext::cmCommandName& cmCommandContext::cmCommandName::operator=( std::string const& name) @@ -474,3 +474,8 @@ bool operator!=(const cmListFileContext& lhs, const cmListFileContext& rhs) { return !(lhs == rhs); } + +std::ostream& operator<<(std::ostream& os, BT const& s) +{ + return os << s.Value; +} diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index 3d3afdf..9f16b16 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -9,6 +9,7 @@ #include // IWYU pragma: keep #include #include +#include #include #include "cmStateSnapshot.h" @@ -169,6 +170,34 @@ private: cmListFileBacktrace(std::shared_ptr top); }; +// Wrap type T as a value with a backtrace. For purposes of +// ordering and equality comparison, only the original value is +// used. The backtrace is considered incidental. +template +class BT +{ +public: + BT(T v = T(), cmListFileBacktrace bt = cmListFileBacktrace()) + : Value(std::move(v)) + , Backtrace(std::move(bt)) + { + } + T Value; + cmListFileBacktrace Backtrace; + friend bool operator==(BT const& l, BT const& r) + { + return l.Value == r.Value; + } + friend bool operator<(BT const& l, BT const& r) + { + return l.Value < r.Value; + } + friend bool operator==(BT const& l, T const& r) { return l.Value == r; } + friend bool operator==(T const& l, BT const& r) { return l == r.Value; } +}; + +std::ostream& operator<<(std::ostream& os, BT const& s); + struct cmListFile { bool ParseFile(const char* path, cmMessenger* messenger, -- cgit v0.12