Skip to main content
22 events
when toggle format what by license comment
Jan 6, 2020 at 14:00 comment added Oliver Schönrock @LaurentLARIZZA Yeah I saw. Yours is good too. This entire question has all got hefty smell of over engineering to it now. The task is trivial. The OP made a meal of it. The highest rated answer is not great. But hey. I am kinda done with it. ;-)
Jan 6, 2020 at 13:56 comment added Laurent LA RIZZA @OliverSchonrock : No. Have a look at my answer, Your freqs variables belong to the predicate. I made them full-fledged funciton objects instead of lambdas.
Jan 6, 2020 at 13:52 comment added Oliver Schönrock @LaurentLARIZZA I added such a version above. Is this what you had in mind?
Jan 6, 2020 at 13:52 comment added Laurent LA RIZZA @OliverSchonrock: Sure. Here you go codereview.stackexchange.com/a/235167/35322
Jan 6, 2020 at 13:51 history edited Oliver Schönrock CC BY-SA 4.0
added 923 characters in body
Jan 6, 2020 at 13:12 comment added Oliver Schönrock @LaurentLARIZZA Yep you could do that. We could debate what "std::all_of" adds here? The key part of the algorithm would go into the predicate lambda, ie tracking which letters have been seen. Why don't you provide an answer that does that, and we can compare?
Jan 6, 2020 at 10:18 comment added Laurent LA RIZZA Well, your algorithm is the same in all 3 cases, it is basically std::all_of with a stateful predicate that determines "whether the current character has never been encountered before". (noting this just because you suggest to use the available algorithms) You're making your predicate implementation vary.
Jan 6, 2020 at 2:49 history edited Oliver Schönrock CC BY-SA 4.0
deleted 8 characters in body
Jan 6, 2020 at 1:59 history edited Oliver Schönrock CC BY-SA 4.0
added 661 characters in body
Jan 6, 2020 at 1:51 history edited Oliver Schönrock CC BY-SA 4.0
added 661 characters in body
Jan 6, 2020 at 1:35 history edited Oliver Schönrock CC BY-SA 4.0
added 609 characters in body
Jan 5, 2020 at 18:43 history edited Oliver Schönrock CC BY-SA 4.0
added 34 characters in body
Jan 5, 2020 at 17:51 comment added Jörg W Mittag Ah, I see. So, C++'s multiset actually behaves less like a multiset but more like a bag ("unordered vector"). I missed that. Today I learned something new!
Jan 5, 2020 at 16:46 comment added Oliver Schönrock @JörgWMittag I would not reach for a multiset here, no. The use case is about frequency (at least in my mind), any freq > 1 must return false. A multiset will store all the characters, inclduding the repeats. So we feed it the complete works of shakespeare gutenberg.org/ebooks/100 . Then you will get a very large (!) multiset. Where an unordered_map (with toupper and assuming ASCII only) will give you at most 26 entries. We want to store unique(!) chars -> int counts. and unordered_map does exactly that.
Jan 5, 2020 at 16:42 comment added Jörg W Mittag Would an unordered_multiset also be a fitting data structure to represent the concept of a "histogram"? I don't know C++, but that's what I would use in a different language (codereview.stackexchange.com/a/233584/1581), even going so far as to implement my own (stackoverflow.com/a/57644639/2988).
Jan 5, 2020 at 16:41 history edited Oliver Schönrock CC BY-SA 4.0
spelling
Jan 5, 2020 at 16:34 comment added Oliver Schönrock Just did a test for a simplified (to get rid of map and iostream boilerplate code) example on godbolt: godbolt.org/z/2R3YdU I copy pasted the ASM for auto and for auto&& and the diff is precisely nil. I am not saying it will always be, in fact this example is "too simple" as it gets SIMD vector optimised etc etc. But in general could we assume that auto&& will not gen "worse" code? I agree it looks "fishy" if you're not used to it though...
Jan 5, 2020 at 16:26 comment added Juho Thanks for the link, interesting point as well!
Jan 5, 2020 at 16:22 history edited Oliver Schönrock CC BY-SA 4.0
include <string>
Jan 5, 2020 at 16:17 comment added Oliver Schönrock I don't disagree. In fact i had it that way and changed last minute before posting. Trying to make for (auto&& e: ..) a habit because "it always works": quuxplusone.github.io/blog/2018/12/15/autorefref-always-works
Jan 5, 2020 at 16:15 comment added Juho I think it would be better to use auto c : str here. For why I wouldn't use auto&& is here, and copying chars is cheap.
Jan 5, 2020 at 16:10 history answered Oliver Schönrock CC BY-SA 4.0