-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
parsercsv: Minor refactor to prefer standard algorithms and datatypes #10871
parsercsv: Minor refactor to prefer standard algorithms and datatypes #10871
Conversation
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.
thanks. a couple minor comments
for (int row = 1; row < tokens.size(); ++row) { | ||
if (locationColumnIndex < tokens[row].size()) { | ||
locations.append(tokens[row][locationColumnIndex]); |
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.
would you mind making this range-based for as well?
09ccbe6
to
5429ad4
Compare
src/library/parsercsv.cpp
Outdated
std::for_each(std::next(std::begin(tokens)), | ||
std::end(tokens), | ||
[&](const auto& token) { | ||
if (locationColumnIndex < token.size()) { | ||
locations.append(token[static_cast<int>( | ||
*locationColumnIndex)]); | ||
} | ||
}); |
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.
Mhmm. the code has just gotten more complex. I didn't anticipate that. My fault. Would you mind reverting the change again. Sorry.
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.
Yeah 😿 , the Mixxx project does not use the range-v3
library yet (hint-hint! 😉)... Then the code would be as simple as:
for(const auto& token: ranges::views::tail(tokens)) {
if (locationColumnIndex < token.size()) {
locations.append(token[static_cast<int>(
*locationColumnIndex)]);
}
}
and many more nice things... 🥲 (range-v3
stuff will arrive into the standard in C++23
)
I agree with you jointly that a range-based approach should be the default writing-style / default way to go.
Will revert back to the previous raw-for-loop form.
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.
Yeah... but expect to wait a bit for that... It was already a pain to switch to C++20...
You're welcome to add the ranges-v3
library as a sort of polyfill to mixxx if you'd like. Do you have any good resources to recommend to learn about ranges? I don't know any mixxx maintainer that knows how to use them (me included).
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.
Interesting question @Swiftb0y, humm, it really depends on one's C++ knowledge.
The tl;dr form is:
- Understanding Standard Library algorithms and why they are important (
C++03
minimum).
- 1.1 Wikipedia - Generic programming - Stepanov–Musser and other generic programming paradigms
- 1.2 Bjarne Stroustrup - What is "generic programming" and what's so great about it?
- Understanding the concept & reasoning behind boost::range (Basically
range-v2
).
(Why is thisrange-v2
? From the History section of boost::range:)
This version introduced Range Adaptors and Range Algorithms. This version 2 is the result of a merge of all of the RangeEx features into Boost.Range.
- 2.1 boost::range - Introduction
- 2.2 boost::range - Range Adapter - Introduction & Motivation
- 2.3 boost::range - Range Algorithm - Introduction & Motivation
- 2.4 Bonus Algorithms Resource: - Christian Aichinger - Boost Range For Humans
- Understanding about
range-v3
Some bonus stuff:
- Sean Parent - GoingNative 2013 - C++ Seasoning
"No raw loops" and "That's a Rotate! 😄"
(Sadly,) This is a quick writeup, so thats all for now! You can always playtest with the concepts about ranges on godbolt.org.
Hope this helps and guides on your ranges-concept journey, ye? 😸
But beware, this programming-paradigm path is quite addicting and could lead you to some "heavier stuff"....! 🙃
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.
Thanks a bunch. I'll definitely check those links out when I find the time.
5429ad4
to
b563ed9
Compare
b563ed9
to
3ae9de6
Compare
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.
lgtm. thanks
Thanks @Swiftb0y for the... swift PR review and merge! Very grateful ye? 😸 🎉 |
As titled. 🎉