Merge 67ae33d908 into c3df6d87d4
This commit is contained in:
commit
098030a5f8
@ -24,6 +24,8 @@ class node {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
friend struct std::hash<node>;
|
||||||
|
|
||||||
node() : m_pRef(new node_ref), m_dependencies{} {}
|
node() : m_pRef(new node_ref), m_dependencies{} {}
|
||||||
node(const node&) = delete;
|
node(const node&) = delete;
|
||||||
node& operator=(const node&) = delete;
|
node& operator=(const node&) = delete;
|
||||||
|
|||||||
23
include/yaml-cpp/node/hash.h
Normal file
23
include/yaml-cpp/node/hash.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef NODE_HASH_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
#define NODE_HASH_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|
||||||
|
#include "yaml-cpp/node/detail/node.h"
|
||||||
|
#include "yaml-cpp/node/node.h"
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
template <>
|
||||||
|
struct hash<YAML::detail::node> {
|
||||||
|
size_t operator()(const YAML::detail::node& key) const noexcept {
|
||||||
|
return hash<YAML::detail::shared_node_ref>()(key.m_pRef);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct hash<YAML::Node> {
|
||||||
|
size_t operator()(const YAML::Node& key) const noexcept {
|
||||||
|
return hash<YAML::detail::node>()(*key.m_pNode);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
|
#endif // NODE_HASH_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
@ -37,6 +37,7 @@ class YAML_CPP_API Node {
|
|||||||
friend class detail::iterator_base;
|
friend class detail::iterator_base;
|
||||||
template <typename T, typename S>
|
template <typename T, typename S>
|
||||||
friend struct as_if;
|
friend struct as_if;
|
||||||
|
friend struct std::hash<Node>;
|
||||||
|
|
||||||
using iterator = YAML::iterator;
|
using iterator = YAML::iterator;
|
||||||
using const_iterator = YAML::const_iterator;
|
using const_iterator = YAML::const_iterator;
|
||||||
|
|||||||
@ -20,5 +20,6 @@
|
|||||||
#include "yaml-cpp/node/detail/impl.h"
|
#include "yaml-cpp/node/detail/impl.h"
|
||||||
#include "yaml-cpp/node/parse.h"
|
#include "yaml-cpp/node/parse.h"
|
||||||
#include "yaml-cpp/node/emit.h"
|
#include "yaml-cpp/node/emit.h"
|
||||||
|
#include "yaml-cpp/node/hash.h"
|
||||||
|
|
||||||
#endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
#endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include "yaml-cpp/node/convert.h"
|
#include "yaml-cpp/node/convert.h"
|
||||||
#include "yaml-cpp/node/detail/impl.h"
|
#include "yaml-cpp/node/detail/impl.h"
|
||||||
#include "yaml-cpp/node/emit.h"
|
#include "yaml-cpp/node/emit.h"
|
||||||
|
#include "yaml-cpp/node/hash.h"
|
||||||
#include "yaml-cpp/node/impl.h"
|
#include "yaml-cpp/node/impl.h"
|
||||||
#include "yaml-cpp/node/iterator.h"
|
#include "yaml-cpp/node/iterator.h"
|
||||||
|
|
||||||
@ -645,6 +646,17 @@ TEST(NodeTest, AccessNonexistentKeyOnConstNode) {
|
|||||||
ASSERT_FALSE(other["5"]);
|
ASSERT_FALSE(other["5"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(NodeTest, NodeIsHashable) {
|
||||||
|
YAML::Node node1(YAML::NodeType::value::Null);
|
||||||
|
YAML::Node node2(YAML::NodeType::value::Null);
|
||||||
|
YAML::Node node3 = node1;
|
||||||
|
std::hash<YAML::Node> hash_func;
|
||||||
|
auto node1_digest = hash_func(node1);
|
||||||
|
ASSERT_EQ(hash_func(node1), node1_digest);
|
||||||
|
ASSERT_NE(hash_func(node2), node1_digest);
|
||||||
|
ASSERT_EQ(hash_func(node3), node1_digest);
|
||||||
|
}
|
||||||
|
|
||||||
class NodeEmitterTest : public ::testing::Test {
|
class NodeEmitterTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void ExpectOutput(const std::string& output, const Node& node) {
|
void ExpectOutput(const std::string& output, const Node& node) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user