-
Notifications
You must be signed in to change notification settings - Fork 1
Add iterator to pini #4
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
Conversation
include/pini/pini.hpp
Outdated
@@ -16,6 +17,13 @@ class pini { | |||
bool load_file(std::filesystem::path const& filename); | |||
bool load_text(std::string_view text); | |||
|
|||
// iteration | |||
|
|||
using const_iterator = std::unordered_map<std::string, std::string>::const_iterator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious: any reason you don't want to alias the map type itself, and instead write down that long type name every time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that you do have the alias as map_type
, so why not use that here?!
include/pini/pini.hpp
Outdated
@@ -35,6 +43,13 @@ class pini { | |||
static void default_callback(std::string_view msg, severity level); | |||
inline static on_msg on_msg_t = &default_callback; | |||
|
|||
bool is_empty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing const correctness
include/pini/pini.hpp
Outdated
@@ -35,6 +43,13 @@ class pini { | |||
static void default_callback(std::string_view msg, severity level); | |||
inline static on_msg on_msg_t = &default_callback; | |||
|
|||
bool is_empty(); | |||
std::size_t size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing const correctness
src/pini.cpp
Outdated
@@ -89,4 +89,11 @@ void pini::default_callback(std::string_view msg, severity level) { | |||
out << msg << '\n'; | |||
} | |||
|
|||
bool pini::is_empty() { return key_value_pairs.empty(); } | |||
std::size_t pini::size() { return key_value_pairs.size(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to inline is_empty()
and size()
(implement in header / in class definition)
if (!pin.load_file(filename)) { return 1; } | ||
for (auto& pair : pin) { std::cout << pair.first << " " << pair.second << '\n'; } | ||
std::cout << pin.size() << " | " << pin.is_empty(); | ||
pin.erase("def"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs more failure cases. Like I said before, you aren't going to see any output in automated runs.
Added:
pini
class that uses the iterator built intostd::unordered_map
std::unordered_map
'sempty()
,size()
clear()
anderase()