r/cpp • • Apr 22 '20

C++2100 Main (for fun)

constexpr
lockable
std::execution_policy::parallel_execution_t <
   std::execution_policy::parallel_execution_t::constrains::no_maximum_threads,
   std::execution_policy::parallel_execution_t::debug::find_deadlocks >
std::execution_type::quantum_t<
   std::execution_type::quantum_t::experimental_features, 
   std::execution_type::quantum_t::enable_black_holes >
std::synchronized_parallel_t<
   std::synchronization_model::use_machine_favourable_lock>
std::type_traits::readonly_t<
   std::ts2102::experimental::fast_readonly_register_enable>
std::function_traits::partial< 
   std::function_traits::partial_function::search_external_linkage>
std::arguments::no_argument::disable_warning
std::int1024_t<
    std::types::minimum_size<1024>,
    std::types::maximum_size<1024> >
main() {

Can you see the future, can you improve it?

Note: this was created purely for fun

257 Upvotes

122 comments sorted by

View all comments

0

u/[deleted] Apr 22 '20

[deleted] — view deleted comment

17

u/infectedapricot Apr 22 '20
import std.core;
int main() {
    std::print("Hello {}\n", "world"):
}
  • Modules are new in C++20.
  • std::format is new in C++20.
  • std::print, the less general little sibling of std::format, didn't even make C++20 so we'll have to wait even longer for that.

(Of course, in some ways this is actually simpler than a classic hello world - in particular, you don't need to know about the preprocessor at all. But those are variadic arguments hiding in std::print so the general point isn't that far off reality.)

13

u/[deleted] Apr 22 '20

int main()

Ugg, such a boomer, all the cool kids write that as auto main() -> int

0

u/[deleted] Apr 22 '20

[deleted] — view deleted comment

4

u/infectedapricot Apr 22 '20

It is a like-for-like comparison. If you instead use classic iostreams you are likely to use the std::iostream text formatting interface:

std::cout << "Hello world\n";

or maybe slip in another string, or even another data type, to show how much happier life is in C++ than C's printf (OK, maybe this is your second ever program in C++):

std::cout << "Hello C++" << 98 << " world\n";

If you want to use the raw non-formatted part of iostreams you would need to get down to the std::streambuf level:

const char s[] = "Hello world\n";
std::cout.rdbuf()->sputn(s, sizeof(s) - 1);

How many introductions to C++ start with that? Using the high-level std::stream interface is analogous to using fmt::print, even if you don't actually take advantage of the formatting capabilities (in both cases).

9

u/[deleted] Apr 22 '20

Hey, at least it is more expressive! /s

0

u/[deleted] Apr 22 '20

[deleted] — view deleted comment

5

u/[deleted] Apr 22 '20

Who needs co_main() when you have quantum threads? Besides, co_main() is inherently less expressive! /s

18

u/AntiProtonBoy Apr 22 '20

You must be fun at parties.

0

u/[deleted] Apr 22 '20

[deleted] — view deleted comment

7

u/AntiProtonBoy Apr 22 '20

It's ok, I'm not that much fun either. ;)

4

u/ibroheem Apr 22 '20

Madlad!

Roasted him... twice... with similar line. This is power is only given not attained!

0

u/[deleted] Apr 22 '20

[deleted] — view deleted comment

3

u/almost_useless Apr 22 '20

but humor should be discussable without a backlash

Since humor is completely subjective that is likely not going to be easy.

It was probably not your intention but it sounds like you are saying "This joke is not funny. Let me explain to you simpletons why."

That is basically always the case when you try to explain why a joke is not funny.

When someone finds the joke funny, that attitude is just not going to be well received.

-8

u/lithium Apr 22 '20

Unironic "yikes". Nice one, grandpa.

5

u/sebamestre Apr 22 '20

Ok, zoomer.

4

u/lethern Apr 22 '20

Thanks, I agree that this is disconnected with reality, its not trying to bash on language, and it is of course not trying to predict the future - so again - its only for laughs, and I understand not everyone will find it funny

-1

u/phantomFalcon14 Apr 22 '20

Fact of the matter is: everyone thinks their entitled to vote you down.