Hacker News new | ask | show | jobs
by pjmlp 18 days ago
C++23 example,

    import std;

    using namespace std;

    int main() {
        vector vec = { 
            "the", "quick", "brown", "fox", 
            "jumped", "over", "the", "lazy", "dog" 
        };

        for (auto&& [i, it] : vec | std::views::enumerate)
            println ("{}:{}", ++i, it);
    }
As I keep mentioning, the features being copied, slowly erode D's relevance.
1 comments

If you prefer writing:

    for (auto&& [i, it] : vec | std::views::enumerate)
        println ("{}:{}", ++i, it);
instead of:

    foreach (i, s; vec)
        writeln(i, ": ", s);
well, what can I say?
I prefer to use the option with better market share.

I am not counting characters, especially when AI completes typing for me.

We may first need to go over what "elegant" means I guess. :)
There is elegant when writing code by hand, and when reviewing code by AI agents.