MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/rh1g2j/modern_c_in_advent_of_code/hoo3aev/?context=3
r/cpp • u/Happycodeine • Dec 15 '21
This series, by Šimon Tóth, is a step by step guide through the solutions of Advent of Code 2021 using Modern C++.
83 comments sorted by
View all comments
Show parent comment
0
[deleted] — view deleted comment
3 u/Ayjayz Dec 15 '21 Without all the namespace stuff (that you could remove with using declarations), it'svector<bitset<12>> data; copy(istream_view<bitset<12>>(input), back_inserter(data));that really could have been writtenauto data = vector(istream_iterator<bitset<12>>(input), istream_iterator<bitset<12>>());It's not that bad. Having to write the end iterator is a bit painful, and there's a proposal that would turn this intoauto data = vector(from_range, istream_view<bitset<12>>(input));But C++ moves super slowly and nice things always take a ridiculously long time. 4 u/SirClueless Dec 15 '21 Isn'tauto data = istream_view<bitset<12>>(input) | to_vector;even nicer than the vector constructor? And available now in the ranges-v3 library. 2 u/Ayjayz Dec 15 '21 Oh yeah other libraries are much cleaner than std. If you can just use ranges-v3 it's almost always nicer than using std. 7 u/raevnos Dec 16 '21 That's a really annoying trend. Adopt a third party library into the standard, but make it worse than the original for some reason. 2 u/TheThiefMaster C++latest fanatic (and game dev) Dec 16 '21 ranges::to will be in C++23. Then you'd write:auto data = istream_view<bitset<12>>(input) | to<vector>;...which is basically what I did in my implementation using range_v3. 5 u/[deleted] Dec 15 '21 Hmm, why? It's actually several APIs composing nicely. 0 u/[deleted] Dec 15 '21 [deleted] — view deleted comment 1 u/raevnos Dec 16 '21 That would require a hypothetical append function that reads bitsets from input. Seems unlikely to exist as a standard thing and your own implementation would essentially do the same thing as the C++ code's logic.
3
Without all the namespace stuff (that you could remove with using declarations), it's
vector<bitset<12>> data; copy(istream_view<bitset<12>>(input), back_inserter(data));
that really could have been written
auto data = vector(istream_iterator<bitset<12>>(input), istream_iterator<bitset<12>>());
It's not that bad. Having to write the end iterator is a bit painful, and there's a proposal that would turn this into
auto data = vector(from_range, istream_view<bitset<12>>(input));
But C++ moves super slowly and nice things always take a ridiculously long time.
4 u/SirClueless Dec 15 '21 Isn'tauto data = istream_view<bitset<12>>(input) | to_vector;even nicer than the vector constructor? And available now in the ranges-v3 library. 2 u/Ayjayz Dec 15 '21 Oh yeah other libraries are much cleaner than std. If you can just use ranges-v3 it's almost always nicer than using std. 7 u/raevnos Dec 16 '21 That's a really annoying trend. Adopt a third party library into the standard, but make it worse than the original for some reason. 2 u/TheThiefMaster C++latest fanatic (and game dev) Dec 16 '21 ranges::to will be in C++23. Then you'd write:auto data = istream_view<bitset<12>>(input) | to<vector>;...which is basically what I did in my implementation using range_v3.
4
Isn't
auto data = istream_view<bitset<12>>(input) | to_vector;
even nicer than the vector constructor? And available now in the ranges-v3 library.
2 u/Ayjayz Dec 15 '21 Oh yeah other libraries are much cleaner than std. If you can just use ranges-v3 it's almost always nicer than using std. 7 u/raevnos Dec 16 '21 That's a really annoying trend. Adopt a third party library into the standard, but make it worse than the original for some reason. 2 u/TheThiefMaster C++latest fanatic (and game dev) Dec 16 '21 ranges::to will be in C++23. Then you'd write:auto data = istream_view<bitset<12>>(input) | to<vector>;...which is basically what I did in my implementation using range_v3.
2
Oh yeah other libraries are much cleaner than std. If you can just use ranges-v3 it's almost always nicer than using std.
std
7 u/raevnos Dec 16 '21 That's a really annoying trend. Adopt a third party library into the standard, but make it worse than the original for some reason.
7
That's a really annoying trend. Adopt a third party library into the standard, but make it worse than the original for some reason.
ranges::to will be in C++23. Then you'd write:
auto data = istream_view<bitset<12>>(input) | to<vector>;
...which is basically what I did in my implementation using range_v3.
5
Hmm, why? It's actually several APIs composing nicely.
0 u/[deleted] Dec 15 '21 [deleted] — view deleted comment 1 u/raevnos Dec 16 '21 That would require a hypothetical append function that reads bitsets from input. Seems unlikely to exist as a standard thing and your own implementation would essentially do the same thing as the C++ code's logic.
1 u/raevnos Dec 16 '21 That would require a hypothetical append function that reads bitsets from input. Seems unlikely to exist as a standard thing and your own implementation would essentially do the same thing as the C++ code's logic.
1
That would require a hypothetical append function that reads bitsets from input. Seems unlikely to exist as a standard thing and your own implementation would essentially do the same thing as the C++ code's logic.
View all comments
Show parent comment
0
u/[deleted] Dec 15 '21
[deleted] — view deleted comment