diff --git a/include/yaml-cpp/node/detail/impl.h b/include/yaml-cpp/node/detail/impl.h index 40c1948..a5cbc0a 100644 --- a/include/yaml-cpp/node/detail/impl.h +++ b/include/yaml-cpp/node/detail/impl.h @@ -58,7 +58,7 @@ struct get_idx::value>::type> { template struct remove_idx { - static bool remove(std::vector&, const Key&, std::size_t*) { + static bool remove(std::vector&, const Key&, std::size_t&) { return false; } }; @@ -69,13 +69,14 @@ struct remove_idx< !std::is_same::value>::type> { static bool remove(std::vector& sequence, const Key& key, - std::size_t* seqSize) { + std::size_t& seqSize) { if (key >= sequence.size()) { return false; } else { - bool defined = sequence[key]->is_defined(); sequence.erase(sequence.begin() + key); - *seqSize -= static_cast(defined && *seqSize > key); + if (seqSize > key) { + --seqSize; + } return true; } } @@ -86,7 +87,7 @@ struct remove_idx::value>::type> { static bool remove(std::vector& sequence, const Key& key, - std::size_t* seqSize) { + std::size_t& seqSize) { return key >= 0 ? remove_idx::remove( sequence, static_cast(key), seqSize) : false; @@ -167,7 +168,7 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) { template inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) { if (m_type == NodeType::Sequence) { - return remove_idx::remove(m_sequence, key, &m_seqSize); + return remove_idx::remove(m_sequence, key, m_seqSize); } else if (m_type == NodeType::Map) { kv_pairs::iterator it = m_undefinedPairs.begin(); while (it != m_undefinedPairs.end()) {