News for hackers. Stuff that matters.
Re:Formatting Text in C++: The Old and the New Ways by BenFrantzDale on Saturday September 16, 2023 @05:18PM (#37538809)
For list comprehension, we have (C++23): `std::ranges::to<std::vector>(items | std::views::filter(shouldInclude) | std::views::transform(f))` it’s not quite `[f(x) for x in items if shouldInclude(x)]` but it’s the same idea.
Re:Formatting Text in C++: The Old and the New Ways by nuancebydefault on Saturday September 16, 2023 @05:24PM (#37538848)
To be honest, if that's the notation, i will not be very eager to jump on cpp23. That said, I admire people who's minds stay open for c++ improvements and make that effort.
Re:Formatting Text in C++: The Old and the New Ways by logicchains on Saturday September 16, 2023 @06:15PM (#37539326)
Well you could write it as

    to<vector>(items | filter(shouldInclude) | transform(f))
if you really want to, but generally C++ programmers prefer to be explicit and include the namespaces.
Re:Formatting Text in C++: The Old and the New Ways by xmonkee on Saturday September 16, 2023 @10:51PM (#37541036)
>but generally C++ programmers prefer to be explicit and include the namespaces.

why, though? Collisions in the stdlib? stdlib is too new to not be the default for these names?

Re:Formatting Text in C++: The Old and the New Ways by Kamq on Sunday September 17, 2023 @12:38AM (#37541574)
The using declaration modifies your namespace.

From the docs:

    namespace X
    {
        using ::f;        // global f is now visible as ::X::f
        using A::g;       // A::g is now visible as ::X::g
    }
 
    void h()
    {
        X::f(); // calls ::f
        X::g(); // calls A::g
    }
Link to docs: https://en.cppreference.com/w/cpp/language/namespace#Using-d...
Re:Formatting Text in C++: The Old and the New Ways by xmonkee on Sunday September 17, 2023 @07:17PM (#37550323)
Thanks
Re:Formatting Text in C++: The Old and the New Ways by Tommstein on Saturday September 16, 2023 @05:42PM (#37539003)
Sweet baby Jesus I thought that was a joke as I started reading it. Still not entirely sure.