3 ms·
how would you write something like #include <print> #include <map> #include <string> int main(int argc, char** argv) { using namesp
by jcelerier 7mo ago
how would you write something like
#include <print>
#include <map>
#include <string>
int main(int argc, char** argv)
{
using namespace std::literals;
std::string foo = "foo:";
foo += argv[0];
std::map<std::string, int> m{
{foo, 123}
, {"count: "s + std::to_string(argc), 456}
};
std::println("{}", m);
}
in C
- hackyhacky 7mo agoSure, there are nice parts of C++. And there are also brain-dead parts that add needless complexity such as: * rvalue references * the difference between auto, decltype, typeof * unreadable template monstrosities * various different flavors of "smart" pointer * the continued existence of footguns relating to UB, dangling pointers, unexpected temporary lifetimes, etc * total absence of a build system or package management * legacy APIs that still take raw pointers * concepts, a half-assed attempt at generic constraints
- pjmlp 7mo agoNo worries, you get some of those in C23, and C2y. Where is C's build system and package management? Yeah, because using _Generic alongside typeof and preprocessor macros isn't half-assed attempt at generics.
- hackyhacky 7mo agoYou misunderstood. Perpetuating C's weaknesses, and then adding additional complexity, is not a defense.
- pjmlp 7mo agoIt kind of is, when the goal was to be TypeScript for C, before this was even a concept. Now ideally we would all be using Modula-2, Ada, Delphi, VB, C#,.... and co, but given that even C compilers are nowadays written in C++, we make do with what we have, while avoiding C flaws as much as possible.
- deleted 7mo ago[deleted]
- pjmlp 7mo agoEven better example, import std; int main(int argc, char** argv) { using namespace std::literals; auto foo = "foo:"s; foo += argv[0]; std::map<std::string, int> m{ {foo, 123} , {"count: "s + std::to_string(argc), 456} }; std::println("{}", m); }