• Sign Up
    Time to claim your honor
  • Training
  • Practice
    Complete challenging Kata to earn honor and ranks. Re-train to hone technique
  • Freestyle Sparring
    Take turns remixing and refactoring others code through Kumite
  • Community
  • Leaderboards
    Achieve honor and move up the global leaderboards
  • Chat
    Join our Discord server and chat with your fellow code warriors
  • Discussions
    View our Github Discussions board to discuss general Codewars topics
  • About
  • Docs
    Learn about all of the different aspects of Codewars
  • Blog
    Read the latest news from Codewars and the community
  • Log In
  • Sign Up
iHector1 Avatar
Name:HECTOR JOSUE GONZALEZ CORTES
Clan:CETI
Member Since:Mar 2021
Last Seen:Nov 2024
Profiles:
Following:2
Followers:2
Allies:2
View Profile Badges
  • Stats
  • Kata
  • Collections
  • Kumite
  • Social
  • Discourse
  • Conversations (12)
  • Replies
  • Authored
  • Needs Resolution
  • Custom User Avatar
    • eurydice5717
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 2 years ago

    :-) note the fmt::join up there is IMHO canonical in the 21rst century..
    Know your STL and get rid of those for loops.

  • Custom User Avatar
    • eurydice5717
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 2 years ago

    YEEEAAHHHHHH this one is excellent!!!
    For F... Sake YOU SURE KNOW YOUR STL!!

    As for me... I'm tired of typing "fmt/ranges" as well as "rangeV3/anyalgo" ... when using format or ranges or views... Keep to C++17
    We need a C++20 compilant compiler there !!

  • Custom User Avatar
    • televisionia
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 2 years ago

    Finally, the universal C++ solution after 16 months of the original kumite. (15 months since my C++ translation.)

  • Custom User Avatar
    • televisionia
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 3 years ago

    Great explanation right there.

  • Custom User Avatar
    • Helaxious
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 3 years ago

    That's much better!

  • Custom User Avatar
    • ryantoll
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 3 years ago

    Ideally, you would want to minimize memory allocations and temporary strings. The previous version would make a new string and do a string concatenation on each loop iteration. There's definitely extra work there that could be removed.

    This version reserves memory ahead of time so there's never more than one memory allocation as the string grows. It also eliminates temporary string objects. Each call to push_back() is only copying a char. Also note the single quotes on the second push_back(). That indicates it's a single char ' ' instead of char array { ' ', '\0' }.

    I also added a reference for the input parameter. You don't need a deep copy of the input and it's generally inadvisable to pass in containers by value since a deep copy could be expensive.

  • Custom User Avatar
    • televisionia
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 3 years ago

    Good explanation! I like the mention of how you can just use using std:: without having to worry about any issues.

  • Custom User Avatar
    • Helaxious
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 3 years ago

    Yes, but it's generally viewed as bad practice because of namespace pollution (everything inside the std namespace gets inside the global namespace, and that leads to all sorts of problems), and I personally prefer to be explicit and just manually type the namespace.

    As an alternative that won't polute the global namespace, you can use using std::something;, it does the same thing, but only to the objects you specify.

  • Custom User Avatar
    • olobeca
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 3 years ago

    u can use "using namespace std"... i have no words

  • Custom User Avatar
    • televisionia
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 3 years ago

    ah alright, me neither, learning a bit of SDL with c++ at the moment

  • Custom User Avatar
    • Helaxious
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 3 years ago

    I'm not very experienced with c++, but I think that can be done with templates, or function overloads.

  • Custom User Avatar
    • televisionia
    • commented on "Digest word into letters (C++ Translation)" kumite
    • 3 years ago

    Yeah, I should figure out how to get it to do multiple data types.

  • © 2025 Codewars
  • About
  • API
  • Blog
  • Privacy
  • Terms
  • Code of Conduct
  • Contact

Confirm

  • Cancel
  • Confirm

Collect: undefined

Loading collection data...