Skip to content

remove items from sequence#582

Merged
jbeder merged 5 commits intojbeder:masterfrom
StarJiao:master
May 14, 2018
Merged

remove items from sequence#582
jbeder merged 5 commits intojbeder:masterfrom
StarJiao:master

Conversation

@StarJiao
Copy link
Copy Markdown
Contributor

@StarJiao StarJiao commented May 2, 2018

based on pull request 471 pullrequest 471
allow users remove items from sequence and keep the type

Copy link
Copy Markdown
Owner

@jbeder jbeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run clang-format on this changelist, since I think some of the indenting is inconsistent.

Comment thread util/demo.cpp Outdated
@@ -0,0 +1,45 @@
#include "yaml-cpp/yaml.h"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a new demo executable, unit tests are sufficient.

Comment thread test/node/node_test.cpp
EXPECT_EQ(0, node.size());
}

TEST(NodeTest, RemoveUnassignedNodeFromMap) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, please add a tests that verifies that if you have a map, where one of the keys is an integer, you can remove it and it's still a map.

Comment thread include/yaml-cpp/node/detail/impl.h Outdated

template <typename Key, typename Enable = void>
struct remove_idx {
static char remove(std::vector<node*>& /* sequence */, const Key& /* key */) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to comment out the variables.

Comment thread include/yaml-cpp/node/detail/impl.h Outdated
}
if (m_type == NodeType::Sequence) {
char result = remove_idx<Key>::remove(m_sequence, key);
if (result == 0) return false;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add curly braces around all "if" statements, even if they're one line.

(The codebase isn't quite consistent there, but I'm trying to enforce it for new code.)

Comment thread include/yaml-cpp/node/detail/impl.h Outdated

template <typename Key, typename Enable = void>
struct remove_idx {
static char remove(std::vector<node*>& /* sequence */, const Key& /* key */) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this return a 'char'? It looks like in all implementations, it either returns 0 or 1.

Comment thread include/yaml-cpp/node/detail/impl.h Outdated
char result = remove_idx<Key>::remove(m_sequence, key);
if (result == 0) return false;
if (result == 1) return true;
convert_to_map(pMemory);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this ever happen? (See above comment.)

Comment thread include/yaml-cpp/node/detail/impl.h Outdated
convert_to_map(pMemory);
}
if (m_type == NodeType::Map) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra newline.

@StarJiao
Copy link
Copy Markdown
Contributor Author

StarJiao commented May 8, 2018

@jbeder Thank you so much and I'm honoured by your reviewing .To be honest, this is the first time to create a pull request and there is many rules i need learn. I am not familiar with C++ . Haha. Thanks again and I will fix all these mistake by your review.

@jbeder
Copy link
Copy Markdown
Owner

jbeder commented May 8, 2018

No problem! Thanks for contributing!

@StarJiao
Copy link
Copy Markdown
Contributor Author

StarJiao commented May 9, 2018

@jbeder Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants