Здравствуйте, bnk, Вы писали:
S>>Стало ли лучше? bnk>Адназначна. Для меня загдка только цифра 67432. Загуглил — почтовый код какого-то города в Канзасе
И в чем же стало лучше?
Т.е. в том то и фишка — он не понимает предназначения кода — а в отрыве от реального мира — все теряет смысл.
Здравствуйте, Shmj, Вы писали:
S>Здравствуйте, bnk, Вы писали:
S>>>Стало ли лучше? bnk>>Адназначна. Для меня загдка только цифра 67432. Загуглил — почтовый код какого-то города в Канзасе
S>И в чем же стало лучше?
S>Т.е. в том то и фишка — он не понимает предназначения кода — а в отрыве от реального мира — все теряет смысл.
Ну так про это и пословица есть — заставь дурака богу молиться
Это не делает его бесполезным. IMHO сейчас вполне себе полезный ассистент.
Когда он сможет догадываться о твоих потаенных желаниях и смыслах, я надеюсь что буду уже на пенсии.
#include <iostream>
#include <string_view>
#include <format>
#include <memory>
#include <concepts>
#include <thread>
#include <vector>
#include <algorithm>
#include <exception>
// Concept constraining to printable string-like typestemplate <typename T>
concept Printable = requires(T a) {
{ std::format("{}", a) } -> std::convertible_to<std::string>;
};
// Compile-time Hello world message
consteval std::string_view getMessage() noexcept {
return"Hello, World!";
}
// Interface for output targets, for DI and testabilitystruct IPrinter {
virtual ~IPrinter() = default;
virtual void print(std::string_view message) const noexcept = 0;
};
// Console printer implementationstruct ConsolePrinter : IPrinter {
void print(std::string_view message) const noexcept override {
try {
// Use std::format for advanced formatting
std::cout << std::format("[Console] {}\n", message);
} catch (...) {
// Fallback on error
std::cout << message << '\n';
}
}
};
// A mock printer to demonstrate polymorphic substitution (e.g. for testing)struct MockPrinter : IPrinter {
mutable std::vector<std::string> messages;
void print(std::string_view message) const noexcept override {
messages.push_back(std::string(message));
}
};
// Generic function templated on Printable concepttemplate<Printable T>
void printMessage(const IPrinter& printer, const T& message) noexcept {
printer.print(std::format("[Message] {}", message));
}
// Thread worker that prints a series of messages safelyvoid threadWorker(const IPrinter& printer, std::vector<std::string_view> messages) noexcept {
for (auto&& msg : messages) {
printMessage(printer, msg);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
}
int main() {
constexpr auto hello = getMessage();
// Dependency injected printerauto printer = std::make_unique<ConsolePrinter>();
// Print initial hello message
printMessage(*printer, hello);
// Spawn multiple threads printing variations of hello
std::vector<std::string_view> variants = {
"Hello, World!",
"Bonjour, le Monde!",
"Hola, Mundo!",
"Hallo, Welt!",
"Ciao, Mondo!"
};
// Runs threads that print messages concurrently
std::vector<std::jthread> threads;
for (int i = 0; i < 3; ++i) {
threads.emplace_back(threadWorker, std::cref(*printer), variants);
}
// Join happens automatically when jthread destructsreturn 0;
}
Здравствуйте, bnk, Вы писали:
S>>Стало ли лучше? bnk>Адназначна. Для меня загдка только цифра 67432. Загуглил — почтовый код какого-то города в Канзасе
Там 674321, а не 67432
Посёлок Молодёжный возле Приаргунска, Забайкальский край.
Я правильно понял, это там на самом деле установлена так называемая Массачусетская Машина?
A return statement ([stmt.return]) in main has the effect of leaving the main function (destroying any objects with automatic storage duration and evaluating any postcondition assertions of main) and calling std::exit with the return value as the argument. If control flows off the end of the compound-statement of main, the effect is equivalent to a return with operand 0 (see also [except.handle]).
A return statement ([stmt.return]) in main has the effect of leaving the main function (destroying any objects with automatic storage duration and evaluating any postcondition assertions of main) and calling std::exit with the return value as the argument. If control flows off the end of the compound-statement of main, the effect is equivalent to a return with operand 0 (see also [except.handle]).
То есть для return-а это не UB, а только для остальных функци. Г — лоГика.
Как много веселых ребят, и все делают велосипед...
bnk>>Адназначна. Для меня загдка только цифра 67432. G>Вот тоже первая мысль, что было бы прикольно у него попросить обосновать свой выбор числа
Возможно это самое случайное число в мире, просто чтобы минимизировать риск clash-а имени функции.
Как много веселых ребят, и все делают велосипед...
Здравствуйте, ononim, Вы писали:
O>>>UB стало, нет return-а у main-а S>>
A return statement ([stmt.return]) in main has the effect of leaving the main function (destroying any objects with automatic storage duration and evaluating any postcondition assertions of main) and calling std::exit with the return value as the argument. If control flows off the end of the compound-statement of main, the effect is equivalent to a return with operand 0 (see also [except.handle]).
O>То есть для return-а это не UB, а только для остальных функци. Г — лоГика.
А main вообще своеобразная функция.
Может быть и `int main()`, и `int main(int, char **)`. Причем по поводу этой логики претензии, вроде как, нужно к чистой Си-шечке применять.
S>А main вообще своеобразная функция. S>Может быть и `int main()`, и `int main(int, char **)`. Причем по поводу этой логики претензии, вроде как, нужно к чистой Си-шечке применять.
Ну с аргументами это как раз таки не проблема, компилятору нет то них дела, это проблемы линкера (которых у сишечного линкера как раз и нету).
А вот то что компилятор по особенному смотрит на отсутствие return у main — это забавно
Как много веселых ребят, и все делают велосипед...
O>Ну с аргументами это как раз таки не проблема, компилятору нет то них дела, это проблемы линкера (которых у сишечного линкера как раз и нету). O>А вот то что компилятор по особенному смотрит на отсутствие return у main — это забавно
Прикол в том, что компилятор ругается, когда пытаюсь один аргумент скормить.
А вот частичный ретурн у мэйна проглатывает, хотя у других выдает ворнинг.
test.cpp:7:5: warning: ‘int main(int)’ takes only zero or two arguments [-Wmain]
7 | int main(int argc)
| ^~~~
test.cpp: In function ‘int f(int)’:
test.cpp:4:1: warning: control reaches end of non-void function [-Wreturn-type]
4 | }