#include <iostream> #include <algorithm> template <typename ... _Args> class hello_world_printer{private: template<typename _Sequence_Argument> constexpr auto push_one(_Sequence_Argument&& arg){ if constexpr(!std::is_integral_v<std::decay_t<_Sequence_Argument»){ return int(arg); } else{ return char(arg); }} std::array<char, sizeof...(_Args)> arguments; public: constexpr hello_world_printer(_Args... args) : arguments({push_one(args)...}){} constexpr auto get() const noexcept{ return arguments;} template<typename _Ch, typename _Tr, typename _Tuple, std::size_t ... _Is> static constexpr void print_impl( std::basic_ostream<_Ch, _Tr>& ostream, const _Tuple& t, std::index_sequence<_Is...>){ ((ostream « (_Is == 0 ? "" : ", ") « std::get<_Is>(t.get())), ...); }}; template <typename _Ch, typename _Tr, typename ... _Args> constexpr std::ostream& operator « ( std::basic_ostream<_Ch, _Tr>& ostream, const hello_world_printer<_Args...>& printer){ ostream « '('; hello_world_printer<_Args...>::print_impl(ostream, printer, std::index_sequence_for<_Args...>());return ostream « ')';} int main(){ std::cout « hello_world_printer('H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd') « std::endl; return EXIT_SUCCESS;}
лайк за EXIT_SUCCESS
Да любой по идее. От 11
вроде ругается, где-то ошибка... ``` main.cpp:24:15: error: storage class specified for a member declaration constexpr auto get() const noexcept { return arguments; } ^ main.cpp:24:31: error: expected ';' at end of declaration list constexpr auto get() const noexcept { return arguments; } ^ ; main.cpp:26:135: error: unexpected character <U+00AB> static constexpr void print_impl(std::basic_ostream<_Ch, _Tr> &ostream, const _Tuple &t, std::index_sequence<_Is...>) { ((ostream « (_Is == 0 ? "" : ", ") « std::get<_Is>(t.get())), ...); } ^~ main.cpp:26:161: error: unexpected character <U+00AB> static constexpr void print_impl(std::basic_ostream<_Ch, _Tr> &ostream, const _Tuple &t, std::index_sequence<_Is...>) { ((ostream « (_Is == 0 ? "" : ", ") « std::get<_Is>(t.get())), ...); } ^~ main.cpp:11:12: error: expected '(' after 'if' if constexpr (!std::is_integral_v < std::decay_t < _Sequence_Argument») ^ main.cpp:28:47: warning: variadic templates are a C++11 extension [-Wc++11-extensions] template <typename _Ch, typename _Tr, typename... _Args> ^ main.cpp:29:1: error: unknown type name 'constexpr' constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ main.cpp:29:16: warning: variable templates are a C++14 extension [-Wc++14-extensions] constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ main.cpp:29:23: error: expected ';' at end of declaration constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ ; main.cpp:29:57: error: use of undeclared identifier '_Ch' constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ main.cpp:29:103: error: use of undeclared identifier '_Args' constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ main.cpp:29:25: error: C++ requires a type specifier for all declarations constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ main.cpp:32:25: error: use of undeclared identifier '_Args' hello_world_printer<_Args...>::print_impl(ostream, printer, std::index_sequence_for<_Args...>()); ^ main.cpp:32:70: error: no member named 'index_sequence_for' in namespace 'std' hello_world_printer<_Args...>::print_impl(ostream, printer, std::index_sequence_for<_Args...>()); ~~~~~^ main.cpp:32:89: error: use of undeclared identifier '_Args' hello_world_printer<_Args...>::print_impl(ostream, printer, std::index_sequence_for<_Args...>()); ^ fatal error: too many errors emitted, stopping now [-ferror-limit=] 4 warnings and 20 errors generated. ```
Значит так милок. Вы забыли включить array.
Замени все » на >> Код был скопирован из вк, а он заменяет >> и <<
Т.е. то, что код написан в 1 строку кода и он буквально выводит хелло ворлд через миллион абстракций, тебя вообще не смущает?)
Я это в 2020 году писал
Что? Кого это вообще смущает?
Обсуждают сегодня