Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toml::array is missing resize() operation #33

Closed
ned14 opened this issue May 22, 2020 · 5 comments
Closed

toml::array is missing resize() operation #33

ned14 opened this issue May 22, 2020 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@ned14
Copy link

ned14 commented May 22, 2020

No description provided.

@ned14 ned14 added the bug Something isn't working label May 22, 2020
@marzer
Copy link
Owner

marzer commented May 22, 2020

@ned14 This is by design; if a call to resize() makes it larger, what should the new node elements be initialized as? Integers with value 0? Empty strings? There isn't really a logical choice here; since more than one is reasonable, that implicitly means that none of them are.

@marzer
Copy link
Owner

marzer commented May 22, 2020

I guess I could provide a resize() operation with a default value, e.g. resize(size_t, string_view) creating strings with the given value if the array needs to grow.

@ned14
Copy link
Author

ned14 commented May 22, 2020

I specifically tried to use it to truncate an overly long array to smaller, and when it wasn't there, that was surprising. I guess .truncate() would do? Otherwise, yes resize with a default value also works, or resize failing if you try to use it for expansion.

@marzer
Copy link
Owner

marzer commented May 22, 2020

Ooh, yes, truncate() is nice and clear, I think. I'll go with that over providing a resize() that's only good for shrinking. I'll also add resize(size_t, <default value>) while I'm at it.

@marzer marzer closed this as completed in 289c95c May 23, 2020
@marzer
Copy link
Owner

marzer commented May 23, 2020

Added in 289c95c:

  • resize(size_t, <default value>)
  • truncate(size_t)
  • max_size(), capacity(), shrink_to_fit() for additional consistency with std::vector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants