{"id":340907,"date":"2022-11-07T15:01:22","date_gmt":"2022-11-07T15:01:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=340907"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=340907","title":{"rendered":"<span>\u0418\u043c\u044f enum&#8217;a C++ \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0442\u0438\u043f\u0430, \u043d\u0435 \u0432\u0430\u0436\u043d\u043e \u044d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u0432 C++ \u2014 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0422\u043e, \u0447\u0442\u043e \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e-\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0432\u0438\u0434 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::type_info::name, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0430\u043d\u0433\u043b\u0438\u043d\u0433\u0430 \u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0435. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, MSVC, IBM, Oracle) \u0441\u043e\u0437\u0434\u0430\u044e\u0442 &#171;\u0443\u0434\u043e\u0431\u043d\u043e\u0435&#187; \u0438\u043c\u044f \u0442\u0438\u043f\u0430, \u0430 \u0432\u043e\u0442 gcc \u0438 clang, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0438\u0441\u043a\u0430\u0436\u0435\u043d\u043d\u043e\u0435 \u0438\u043c\u044f, \u043a\u043e\u0442\u043e\u0440\u043ee \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440  abi::__cxa_demangle. \u0427\u0442\u043e\u0431\u044b \u0432\u0441\u044f \u044d\u0442\u0430 \u043c\u0430\u0433\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c RTTI, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u0436\u0435 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435-\u0442\u043e \u0432\u0440\u0435\u0434\u0435\u043d, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u0436\u0438\u0440\u0430\u0435\u0442 \u0434\u0440\u0430\u0433\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/3ea\/400\/6e2\/3ea4006e2ae2002cde3cbd37c83dfd50.jpg\" width=\"642\" height=\"389\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3ea\/400\/6e2\/3ea4006e2ae2002cde3cbd37c83dfd50.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<hr\/>\n<p>\u0412 \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0421++ \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u0430\u043a\u0430\u044f-\u043b\u0438\u0431\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0421++20 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043f\u0440\u043e\u043f\u043e\u0437\u0430\u043b\u044b (<a href=\"https:\/\/en.cppreference.com\/w\/cpp\/keyword\/reflexpr\" rel=\"noopener noreferrer nofollow\">https:\/\/en.cppreference.com\/w\/cpp\/keyword\/reflexpr<\/a>), \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u044f\u0437\u044b\u043a \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. \u0412\u043e\u0442 \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a \u0432\u044b\u0434\u0430\u0435\u0442 clang \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c. <\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;typeinfo> #include &lt;cxxabi.h>  struct Simple { }; struct Base { virtual ~Base() = default; }; struct Derived : Base {}; enum Enum { one = 4, two = 2 };   int main() {     Base b1;     Derived d1;     Simple c1;     Enum eenum;       const Base *pb = &amp;b1;     std::cout &lt;&lt; typeid(*pb).name() &lt;&lt; '\\n';     pb = &amp;d1;     std::cout &lt;&lt; typeid(*pb).name() &lt;&lt; '\\n';          std::cout &lt;&lt; typeid(eenum).name() &lt;&lt; '\\n';          std::cout &lt;&lt; typeid(c1).name() &lt;&lt; '\\n';          int     status;     char   *realname;      realname = abi::__cxa_demangle(typeid(*pb).name(), 0, 0, &amp;status);     std::cout &lt;&lt; typeid(*pb).name() &lt;&lt; \"\\t=> \" &lt;&lt; realname &lt;&lt; \"\\t: \" &lt;&lt; status &lt;&lt; '\\n'; }  $> 4Base    7Derived    4Enum    6Simple    7Derived        => Derived      : 0<\/code><\/pre>\n<p>\u0422.\u0435. \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u043c \u043d\u0430\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<p><strong>\u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0438\u043f \u0447\u0435\u0440\u0435\u0437 \u043c\u0430\u043a\u0440\u043e\u0441?<\/strong><\/p>\n<p>\u041d\u0443 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043c\u043e\u0436\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u044b \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e. \u041f\u043e\u0432\u0442\u043e\u0440\u044e\u0441\u044c, \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u044f\u0432\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u0434\u0430\u044e\u0449\u0438\u0445 \u0438\u043c\u044f \u0442\u0438\u043f\u0430 \u0432\u043d\u0435 <strong>typeid<\/strong>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u0430\u043c \u0442\u0438\u043f.<\/p>\n<pre><code class=\"cpp\">#define TYPE_NAME(x) #x std::cout &lt;&lt; TYPE_NAME(std::string) &lt;&lt; std::endl;<\/code><\/pre>\n<p> \u0412\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c, \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432. \u041c\u0430\u043a\u0440\u043e\u0441\u0443 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0432 \u0441\u0442\u0440\u043e\u043a\u0443, \u0445\u043e\u0442\u044c \u0441\u043b\u043e\u043d\u0430, \u0445\u043e\u0442\u044c \u043c\u043e\u0441\u044c\u043a\u0443. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0447\u0443\u0442\u044c \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435.<\/p>\n<pre><code class=\"cpp\">template &lt;typename T> void print(int x) {   std::cout &lt;&lt; TYPE_NAME(T) &lt;&lt; std::endl;   std::cout &lt;&lt; TYPE_NAME(decltype(x)) &lt;&lt; std::endl; }  $> T    decltype(x)<\/code><\/pre>\n<p><strong>\u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0438\u043f \u0447\u0435\u0440\u0435\u0437 \u0448\u0430\u0431\u043b\u043e\u043d?<\/strong><\/p>\n<pre><code class=\"cpp\">template &lt;typename T> void bad_function();<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u0448\u0438\u0431\u0430\u043b\u0438\u0441\u044c \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0432\u0438\u0434\u0435\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043f\u0440\u043e\u0441\u0442\u044b\u043d\u044e \u0442\u0435\u043a\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u044b\u043b\u043e \u043f\u0440\u043e <code>bad_function&lt;foo>()<\/code>, \u0442.\u0435. \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u0441\u0442\u0430\u043b \u0438 \u0438\u043c\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0438\u043c\u044f \u0435\u0451 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/12c\/bea\/b13\/12cbeab131782bc7fa22f0241c504268.jpg\" alt=\"\u0417\u0434\u0435\u0441\u044c \u0431\u044b\u043b\u0430 \u0448\u0443\u0442\u043a\u0430 \u043f\u0440\u043e \u043f\u043b\u044e\u0441\u044b.\" title=\"\u0417\u0434\u0435\u0441\u044c \u0431\u044b\u043b\u0430 \u0448\u0443\u0442\u043a\u0430 \u043f\u0440\u043e \u043f\u043b\u044e\u0441\u044b.\" width=\"351\" height=\"143\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/12c\/bea\/b13\/12cbeab131782bc7fa22f0241c504268.jpg\" data-blurred=\"true\"\/><figcaption>\u0417\u0434\u0435\u0441\u044c \u0431\u044b\u043b\u0430 \u0448\u0443\u0442\u043a\u0430 \u043f\u0440\u043e \u043f\u043b\u044e\u0441\u044b.<\/figcaption><\/figure>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430? \u0418\u0441\u0441\u043b\u0435\u0434\u0443\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438\u043c\u044f \u0442\u0438\u043f\u0430 \u0438\u043b\u0438 \u044d\u043d\u0430\u043c\u0430, \u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u043d\u0430\u043c\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>__function__<\/strong>. \u0427\u0442\u043e \u043f\u043e \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f? \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432 \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0432\u0438\u0434\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0432 \u043c\u0435\u0441\u0442\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"1c\">clang __function__ __FUNCTION__ Defined as a string literal that contains the undecorated name of the enclosing function. The macro is defined only within a function. The __FUNCTION__  macro isn't expanded if you use the \/EP or \/P compiler option. For an example of usage, see the __FUNCNAME__ macro.  __PRETTY_FUNCTION__ clang __PRETTY_FUNCTION__ is a gcc extension that is mostly the same as __FUNCTION__, except that for C++ functions it contains the \"pretty\" name of the function including  the signature of the function. Visual C++ has a similar (but not quite identical)  extension, __FUNCSIG__ .<\/code><\/pre>\n<p><strong>(<\/strong><a href=\"https:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2004\/n1642.html\" rel=\"noopener noreferrer nofollow\">https:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2004\/n1642.html<\/a>)<strong>, <\/strong>\u042d\u0442\u0430 \u0441\u043a\u0440\u044b\u0442\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f,<strong> <\/strong>\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0441\u0442\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0430\u043a <strong>const char* <\/strong>. \u041e\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0435 \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<pre><code class=\"cpp\">struct Simple { };  template &lt;typename T> std::string test() {   return __PRETTY_FUNCTION__; }  int main() {     std::cout &lt;&lt; test&lt;std::string>() &lt;&lt; std::endl;     std::cout &lt;&lt; test&lt;Simple>() &lt;&lt; std::endl; }  $> std::string test() [with T = std::__cxx11::basic_string&lt;char>; std::string = std::__cxx11::basic_string&lt;char>]    std::string test() [with T = Simple; std::string = std::__cxx11::basic_string&lt;char>]<\/code><\/pre>\n<p>C \u0442\u0430\u043a\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0430\u0440\u0441\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u0442 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 <strong>string<\/strong> \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438. \u041f\u043e\u0438\u0441\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u044f\u0436\u0435\u043b\u043e\u0432\u0430\u0442\u044b\u043c, \u0438 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043d\u043e \u043c\u044b \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0435\u043c.<\/p>\n<pre><code class=\"cpp\">struct Simple { };  template &lt;typename T> struct TypeNameHelper {     static std::string TypeName(void) {         const auto prefix   = std::string{\"[with T = \"};         const auto suffix   = std::string{\";\"};         const auto function = std::string{__PRETTY_FUNCTION__};              const auto start    = function.find(prefix) + prefix.size();         const auto end      = function.rfind(suffix);              const auto result   = function.substr(start, (end - start));              return result;     } };  template &lt;typename T> std::string TypeName(void) {     return TypeNameHelper&lt;T>::TypeName(); }  $> std::__cxx11::basic_string&lt;char> Simple<\/code><\/pre>\n<p>\u0415\u0449\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0443\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0435 \u0438\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u0441 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438, \u0438\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0441 -O2\/3 \u043a\u043b\u044e\u0447\u0430\u043c\u0438. \u041d\u0430 \u0441\u0431\u043e\u0440\u043a\u0435 \u0441 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430 \u043c\u0435\u0441\u0442\u0435 \u0441 -O3 (<a href=\"https:\/\/onlinegdb.com\/cjE1_rU9I\" rel=\"noopener noreferrer nofollow\">https:\/\/onlinegdb.com\/cjE1_rU9I<\/a>) \u0442\u043e\u0436\u0435.  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b. <\/p>\n<pre><code class=\"cpp\">enum test_enum { te_first, te_second, te_third, te_count }; int main() {    std::cout &lt;&lt; TypeName&lt;test_enum>() &lt;&lt; std::endl; }  $> test_enum<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0432 \u0432\u044b\u0432\u043e\u0434\u0435 \u0443\u0436\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u044d\u043d\u0430\u043c\u0430, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u043d\u0430\u043c\u0430, \u043c\u0430\u0433\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0435\u0449\u0435 \u043d\u0435\u0442, \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<pre><code class=\"cpp\">template &lt;typename T, T V> struct TypeNameHelper {     static const char* TypeName(void) {         static const size_t size = sizeof(__PRETTY_FUNCTION__);         static char typeName[size] = {};         memcpy(typeName, __PRETTY_FUNCTION__ , size - 1u);         return typeName;     } };  template &lt;typename T, T V> const char* TypeName(void) {     return TypeNameHelper&lt;T, V>::TypeName(); }  enum test_enum { te_first, te_second, te_third, te_count }; int main() {    std::cout &lt;&lt; TypeName&lt;test_enum, te_second>() &lt;&lt; std::endl; }  $> test_enum; T V = te_first<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0437\u0430\u0434\u0430\u0447\u0435 \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430, \u043a\u0440\u043e\u043c\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043e\u0431\u044b\u0447\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0435\u0451 \u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <strong>std::integer_sequence<\/strong> \u0438 fold expressions, \u0442\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u044d\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u044d\u043d\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u043d \u0441 &#171;\u0434\u044b\u0440\u043a\u0430\u043c\u0438&#187;.<\/p>\n<pre><code class=\"cpp\">template&lt;typename T, T... ints> void print_sequence(std::integer_sequence&lt;T, ints...> int_seq) {     std::cout &lt;&lt; \"The sequence of size \" &lt;&lt; int_seq.size() &lt;&lt; \": \";     ((std::cout &lt;&lt; ints &lt;&lt; ' '), ...);     std::cout &lt;&lt; '\\n'; }  int main() {      print_sequence(std::make_integer_sequence&lt;int, 20>{}); }  $> The sequence of size 20: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <\/code><\/pre>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u044f \u0432\u0441\u0435 \u043c\u044b\u0441\u043b\u0438 \u0432 \u043a\u0443\u0447\u0443 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043f\u0440\u043e\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<br \/>1. \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u044d\u043d\u0430\u043c \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0434\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0447\u0435\u0440\u0435\u0437 <strong>std::integer_sequence<\/strong>  <strong><br \/><\/strong>2. \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <strong>TypeName <\/strong>\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 <br \/>3. \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 { \u0438\u043c\u044f, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 } \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c<\/p>\n<p><strong>\u0420\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u043d\u0430\u043c\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 (\u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e)<\/strong><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u0442\u043e\u043c\u043b\u044f\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u043e\u0439, \u0431\u0443\u0434\u0443 \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u043f\u043e\u044f\u0441\u043d\u044f\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b. \u041a\u0430\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0443\u0431\u0435\u0434\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u044d\u043d\u0430\u043c \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0435 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043b\u0433\u043e \u0432 \u043f\u043b\u0430\u043d\u0435 \u043f\u0440\u043e\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u044f \u0434\u043e\u0431\u0438\u043b\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u044b, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043a\u043b\u0430\u043d\u0433\u0430 \u0438 \u0441\u0442\u0443\u0434\u0438\u0438, c gcc, \u0443\u0432\u044b, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. <\/p>\n<ul>\n<li>\n<p>count_values &#8212; \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0441\u0447\u0435\u0442 \u0447\u0438\u0441\u043b\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u044d\u043d\u0430\u043c\u0435<\/p>\n<\/li>\n<li>\n<p>make_tokens &#8212; \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u044d\u043d\u0430\u043c\u0430 \u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0438\u0445 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0430 { \u0438\u043c\u044f, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 }<\/p>\n<\/li>\n<li>\n<p>tokens &#8212; \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u044d\u043d\u0430\u043c\u0430, \u0438 \u0438\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>make_name &#8212; c \u043f\u043e\u043c\u043e\u0449\u044c\u044e __PRETTY_FUNCTION__ \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>token_holder &#8212; \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u0440\u044b\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">struct token {     const char * name;     s32 id; };  template&lt;typename enum_type, enum_type begin, enum_type end> struct token_holder {     constexpr static inline int count_values(enum_type type) {         return (type != end)             ? count_values((enum_type)(s32(type)+1))             : (s32(type)+1);     }      static constexpr u32 N = count_values(begin);     using tokens = std::array&lt;token, N+1>; \/\/ because have {0, 0} in last element      template&lt;typename e_enum_type, e_enum_type enum_value>     constexpr token make_name() {         return { enum_name&lt;e_enum_type, enum_value>().name(), enum_value };     }      template&lt;typename e_enum_type, u32... Indices>     constexpr tokens make_tokens_helper(std::integer_sequence&lt;u32, Indices...>) {         tokens ts = { make_name&lt;e_enum_type, (e_enum_type)Indices>()... };         ts[N] = {0, 0};         return ts;     }      template&lt;typename e_enum_type>     constexpr tokens make_tokens() {         return make_tokens_helper&lt;e_enum_type>( std::make_integer_sequence&lt;u32, N>{});     }       constexpr operator const token *() const { return values.unsafe_ptr(); }     constexpr token *data() const { return values.unsafe_ptr(); }     constexpr token_holder() : values{make_tokens&lt;enum_type>()} {}      tokens values; };<\/code><\/pre>\n<p><strong>\u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u043d\u0430\u043c\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 (\u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435)<\/strong><\/p>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u043e \u0447\u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u0442\u044b\u0439 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d \u044d\u043d\u0430\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0435<\/p>\n<pre><code class=\"cpp\">static const char *enum_name&lt;test_enum, te_first>::helper_name()   [enum_type = test_enum, enum_value = te_first, value = te_first]<\/code><\/pre>\n<p>\u0438 \u0438\u0449\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 <strong>&#171;=&#187;<\/strong>, \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430. static \u043a\u0432\u0430\u043b\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0442\u0443\u0442 \u043d\u0443\u0436\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<pre><code class=\"cpp\">template&lt;typename enum_type, enum_type enum_value> class enum_name final {     \/\/ Helper function that directly takes an enum_type value template parameter to get the name of the classes template enum type value as a string.     template &lt;enum_type value>     static const char* helper_name() {         \/\/ Clang compiler format:   __PRETTY_FUNCTION__          \/\/ = static const char *enum_name&lt;ENUM_TYPE_NAME, ENUM_TYPE_NAME::ENUM_VALUE_NAME>::helper_value() [enum_type = ENUM_TYPE_NAME, enum_value = ENUM_TYPE_NAME::ENUM_VALUE_NAME, value = ENUM_TYPE_NAME::ENUM_VALUE_NAME]         \/\/ static const char *enum_name&lt;test_enum, te_first>::helper_name() [enum_type = test_enum, enum_value = te_first, value = te_first]          \/\/ MSVC compiler format:    __FUNCSIG__                  \/\/ = const char *__cdecl enum_name&lt;enum ENUM_TYPE_NAME,ENUM_VALUE>::helper_value&lt;ENUM_TYPE_NAME::ENUM_VALUE_NAME>(void)         \/\/ const char *__cdecl enum_name&lt;enum test_enum,0>::helper_name&lt;te_first>(void)          static const unsigned long long function_name_length = sizeof(__PRETTY_FUNCTION__);         static const std::string function_name(__PRETTY_FUNCTION__);         static const unsigned long long type_name_start  = function_name.rfind('=') + 2;         static const unsigned long long type_name_end    = function_name_length - 2;         static const unsigned long long type_name_length = type_name_end - type_name_start;         static const std::string type_name_string = function_name.substr((size_t)type_name_start, (size_t)type_name_length);         return type_name_string.c_str();     }  public:     static const char* name() { return helper_name&lt;enum_value>(); }\/\/ Get the name of the classes template enum type and value as a string. };<\/code><\/pre>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435, \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0443\u0436\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u043d\u0430\u043c\u043e\u0432 (<a href=\"https:\/\/onlinegdb.com\/YpqJ1byp5\" rel=\"noopener noreferrer nofollow\">https:\/\/onlinegdb.com\/YpqJ1byp5<\/a>)<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/710\/415\/649\/71041564948475ba4235f70a390ddcec.png\" width=\"861\" height=\"283\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/710\/415\/649\/71041564948475ba4235f70a390ddcec.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>\u0418\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 string (\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e)<\/strong><\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 std::string_view, \u043d\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e. \u041e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <strong>string <\/strong>\u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u0438\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, <strong>rfind<\/strong> \u0438 <strong>substr<\/strong>. <strong>__PRETTY_FUNCTION__ <\/strong>\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430) \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438 \u0431) \u0431\u0435\u0437 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0430\u043b\u043e\u043a\u0430\u0446\u0438\u0438, \u043d\u0443 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u043e\u0439. \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f memcpy, \u0438\u043b\u0438 \u0446\u0438\u043a\u043b\u0430\u043c\u0438 \u0432 constexpr \u0434\u043b\u044f \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f, \u043d\u043e \u0446\u0438\u043a\u043b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044e \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e<strong> rfind <\/strong>(\u044d\u0442\u043e\u0436 \u043a\u043e\u043c\u043f\u0430\u0439\u043b \u0442\u0430\u0439\u043c, \u043a\u0442\u043e \u0435\u0433\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430). \u0410 \u0432\u043e\u0442 substr \u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0441\u043c\u043e\u0433, \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0433\u0443\u0433\u043b\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 (<a href=\"https:\/\/stackoverflow.com\/questions\/56471708\/c-compile-time-substring\" rel=\"noopener noreferrer nofollow\">https:\/\/stackoverflow.com\/questions\/56471708\/c-compile-time-substring<\/a>) \u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432 std::string_view. \u041d\u0443 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c <strong>\u0441_str<\/strong>(), \u043a\u0443\u0434\u0430 \u0436\u0435 \u0431\u0435\u0437 \u044d\u0442\u043e\u0439 \u043b\u0435\u0433\u0435\u043d\u0434\u0430\u0440\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043f\u043b\u044e\u0441\u0430\u0445. <strong>constexpr <\/strong>\u0432 \u0432\u044b\u0437\u043e\u0432\u0430\u0445<strong> <\/strong>\u043d\u0443\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u043c\u043e\u0433 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u043f\u0440\u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0430\u0446\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0432 \u043c\u0435\u0441\u0442\u0430\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<pre><code class=\"cpp\">template &lt;unsigned long long length> class string_literal final { const char string[length];  public: template&lt;unsigned long long... indexes>   const string_literal(const char(&amp;raw_string)[sizeof...(indexes)], std::integer_sequence&lt;unsigned long long, indexes...> index_sequence) : string{ raw_string[indexes]... } { static_cast&lt;void>(index_sequence); }  constexpr const char* c_str() const { return this->string; }  template&lt;unsigned long long substring_start, unsigned long long substring_length, unsigned long long... substring_indexes> constexpr const string_literal&lt;substring_length + 1> substr(std::integer_sequence&lt;unsigned long long, substring_indexes...> substring_index_sequence) const { static_cast&lt;void>(substring_index_sequence); return string_literal&lt;substring_length + 1>({ this->string[substring_start + substring_indexes]..., '\\0' }, std::make_integer_sequence&lt;unsigned long long, substring_length + 1>{}); }  constexpr unsigned long long find(const char character, const unsigned long long starting_index = 0) const { return((starting_index >= length) ? 0xFFFFFFFFFFFFFFFF : ((this->string[starting_index] == character) ? starting_index : this->find(character, starting_index + 1))); }  constexpr unsigned long long rfind(const char character, const unsigned long long starting_index = length - 1) const { return((starting_index == 0)  ? ((this->string[starting_index] == character) ? starting_index : 0xFFFFFFFFFFFFFFFF)       : ((this->string[starting_index] == character) ? starting_index : this->rfind(character, starting_index - 1))); } };<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0441\u043e\u0431\u0440\u0430\u0432 \u0432\u0441\u0435 \u0447\u0430\u0441\u0442\u0438 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u0435, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f enum&#8217;\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0438\u0441\u043a\u0430\u0445 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0442\u0430\u043a\u0436\u0435 \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0435\u0433\u043e \u0438\u043c\u0435\u043d\u0438. <\/p>\n<pre><code class=\"cpp\">enum test_enum { te_first, te_second, te_third, te_count };  int main() {     const token_holder&lt;test_enum, te_first, te_count> test_tokens;      for (auto &amp;s: test_tokens.values)         std::cout &lt;&lt; \"{\" &lt;&lt; (s.name ? s.name : \"null\")                    &lt;&lt; \", \" &lt;&lt; s.id &lt;&lt; \" }\"                   &lt;&lt; std::endl; }  $>  {te_first, 0 }     {te_second, 1 }     {te_third, 2 }     {te_count, 3 }     {null, 0 }<\/code><\/pre>\n<p><strong>\u0412\u043c\u0435\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u043e\u0432<\/strong><\/p>\n<p>\u041d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u0447\u0435\u0441\u0442\u0432\u0430, \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u043d\u0430\u044f \u043c\u0430\u0433\u0438\u044f. \u0425\u043e\u0442\u044f \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0431\u044b\u0442\u044c \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0438\u043c\u0435\u043d\u0438 \u0442\u0438\u043f\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0445\u0430\u0447\u0438\u0442\u044c \u0441\u0430\u043c \u044f\u0437\u044b\u043a (\u044f \u043e\u0431\u043e\u0436\u0430\u044e \u043f\u043b\u044e\u0441\u044b \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u0432\u043e\u0440\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0434\u0438\u0447\u044c), \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430. \u0411\u044b\u043b\u043e \u043b\u0438 \u044d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0438 \u043f\u043e\u0442\u0430\u0449\u0443 \u043b\u0438 \u044d\u0442\u043e \u0432 \u043f\u0440\u043e\u0434: \u0432\u0440\u044f\u0434 \u043b\u0438, \u0431\u044b\u043b\u043e \u043b\u0438 \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e &#8212; \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043f\u043e\u0438\u0449\u0438\u0442\u0435 magic_enum \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435, \u043d\u043e \u0435\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u043d\u0443\u0436\u0435\u043d \u0441++17 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b, \u044f \u0436\u0435 \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u0433\u0443\u043b\u044f\u043b\u0441\u044f \u043f\u043e \u0437\u0435\u043c\u043b\u044f\u043c \u0434\u0440\u0430\u043a\u043e\u043d\u043e\u0432 11\\14 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430.<\/p>\n<p>\u0417.\u042b. \u043a\u043e\u0434 \u0442\u0443\u0442 (<a href=\"https:\/\/github.com\/dalerank\/tokenum\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/dalerank\/tokenum<\/a>)<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/697198\/\"> https:\/\/habr.com\/ru\/post\/697198\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0442\u0438\u043f\u0430, \u043d\u0435 \u0432\u0430\u0436\u043d\u043e \u044d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u0432 C++ \u2014 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0422\u043e, \u0447\u0442\u043e \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e-\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0432\u0438\u0434 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::type_info::name, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0430\u043d\u0433\u043b\u0438\u043d\u0433\u0430 \u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0435. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, MSVC, IBM, Oracle) \u0441\u043e\u0437\u0434\u0430\u044e\u0442 &#171;\u0443\u0434\u043e\u0431\u043d\u043e\u0435&#187; \u0438\u043c\u044f \u0442\u0438\u043f\u0430, \u0430 \u0432\u043e\u0442 gcc \u0438 clang, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0438\u0441\u043a\u0430\u0436\u0435\u043d\u043d\u043e\u0435 \u0438\u043c\u044f, \u043a\u043e\u0442\u043e\u0440\u043ee \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440  abi::__cxa_demangle. \u0427\u0442\u043e\u0431\u044b \u0432\u0441\u044f \u044d\u0442\u0430 \u043c\u0430\u0433\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c RTTI, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u0436\u0435 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435-\u0442\u043e \u0432\u0440\u0435\u0434\u0435\u043d, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u0436\u0438\u0440\u0430\u0435\u0442 \u0434\u0440\u0430\u0433\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<hr\/>\n<p>\u0412 \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0421++ \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u0430\u043a\u0430\u044f-\u043b\u0438\u0431\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0421++20 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043f\u0440\u043e\u043f\u043e\u0437\u0430\u043b\u044b (<a href=\"https:\/\/en.cppreference.com\/w\/cpp\/keyword\/reflexpr\" rel=\"noopener noreferrer nofollow\">https:\/\/en.cppreference.com\/w\/cpp\/keyword\/reflexpr<\/a>), \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u044f\u0437\u044b\u043a \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. \u0412\u043e\u0442 \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a \u0432\u044b\u0434\u0430\u0435\u0442 clang \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c. <\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;typeinfo> #include &lt;cxxabi.h>  struct Simple { }; struct Base { virtual ~Base() = default; }; struct Derived : Base {}; enum Enum { one = 4, two = 2 };   int main() {     Base b1;     Derived d1;     Simple c1;     Enum eenum;       const Base *pb = &amp;b1;     std::cout &lt;&lt; typeid(*pb).name() &lt;&lt; '\\n';     pb = &amp;d1;     std::cout &lt;&lt; typeid(*pb).name() &lt;&lt; '\\n';          std::cout &lt;&lt; typeid(eenum).name() &lt;&lt; '\\n';          std::cout &lt;&lt; typeid(c1).name() &lt;&lt; '\\n';          int     status;     char   *realname;      realname = abi::__cxa_demangle(typeid(*pb).name(), 0, 0, &amp;status);     std::cout &lt;&lt; typeid(*pb).name() &lt;&lt; \"\\t=> \" &lt;&lt; realname &lt;&lt; \"\\t: \" &lt;&lt; status &lt;&lt; '\\n'; }  $> 4Base    7Derived    4Enum    6Simple    7Derived        => Derived      : 0<\/code><\/pre>\n<p>\u0422.\u0435. \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u043c \u043d\u0430\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<p><strong>\u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0438\u043f \u0447\u0435\u0440\u0435\u0437 \u043c\u0430\u043a\u0440\u043e\u0441?<\/strong><\/p>\n<p>\u041d\u0443 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043c\u043e\u0436\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u044b \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e. \u041f\u043e\u0432\u0442\u043e\u0440\u044e\u0441\u044c, \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u044f\u0432\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u0434\u0430\u044e\u0449\u0438\u0445 \u0438\u043c\u044f \u0442\u0438\u043f\u0430 \u0432\u043d\u0435 <strong>typeid<\/strong>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u0430\u043c \u0442\u0438\u043f.<\/p>\n<pre><code class=\"cpp\">#define TYPE_NAME(x) #x std::cout &lt;&lt; TYPE_NAME(std::string) &lt;&lt; std::endl;<\/code><\/pre>\n<p> \u0412\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c, \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432. \u041c\u0430\u043a\u0440\u043e\u0441\u0443 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0432 \u0441\u0442\u0440\u043e\u043a\u0443, \u0445\u043e\u0442\u044c \u0441\u043b\u043e\u043d\u0430, \u0445\u043e\u0442\u044c \u043c\u043e\u0441\u044c\u043a\u0443. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0447\u0443\u0442\u044c \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435.<\/p>\n<pre><code class=\"cpp\">template &lt;typename T> void print(int x) {   std::cout &lt;&lt; TYPE_NAME(T) &lt;&lt; std::endl;   std::cout &lt;&lt; TYPE_NAME(decltype(x)) &lt;&lt; std::endl; }  $> T    decltype(x)<\/code><\/pre>\n<p><strong>\u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0438\u043f \u0447\u0435\u0440\u0435\u0437 \u0448\u0430\u0431\u043b\u043e\u043d?<\/strong><\/p>\n<pre><code class=\"cpp\">template &lt;typename T> void bad_function();<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u0448\u0438\u0431\u0430\u043b\u0438\u0441\u044c \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0432\u0438\u0434\u0435\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043f\u0440\u043e\u0441\u0442\u044b\u043d\u044e \u0442\u0435\u043a\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u044b\u043b\u043e \u043f\u0440\u043e <code>bad_function&lt;foo>()<\/code>, \u0442.\u0435. \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u0441\u0442\u0430\u043b \u0438 \u0438\u043c\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0438\u043c\u044f \u0435\u0451 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.<\/p>\n<figure class=\"\"><figcaption>\u0417\u0434\u0435\u0441\u044c \u0431\u044b\u043b\u0430 \u0448\u0443\u0442\u043a\u0430 \u043f\u0440\u043e \u043f\u043b\u044e\u0441\u044b.<\/figcaption><\/figure>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430? \u0418\u0441\u0441\u043b\u0435\u0434\u0443\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438\u043c\u044f \u0442\u0438\u043f\u0430 \u0438\u043b\u0438 \u044d\u043d\u0430\u043c\u0430, \u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u043d\u0430\u043c\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>__function__<\/strong>. \u0427\u0442\u043e \u043f\u043e \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f? \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432 \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0432\u0438\u0434\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0432 \u043c\u0435\u0441\u0442\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"1c\">clang __function__ __FUNCTION__ Defined as a string literal that contains the undecorated name of the enclosing function. The macro is defined only within a function. The __FUNCTION__  macro isn't expanded if you use the \/EP or \/P compiler option. For an example of usage, see the __FUNCNAME__ macro.  __PRETTY_FUNCTION__ clang __PRETTY_FUNCTION__ is a gcc extension that is mostly the same as __FUNCTION__, except that for C++ functions it contains the \"pretty\" name of the function including  the signature of the function. Visual C++ has a similar (but not quite identical)  extension, __FUNCSIG__ .<\/code><\/pre>\n<p><strong>(<\/strong><a href=\"https:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2004\/n1642.html\" rel=\"noopener noreferrer nofollow\">https:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2004\/n1642.html<\/a>)<strong>, <\/strong>\u042d\u0442\u0430 \u0441\u043a\u0440\u044b\u0442\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f,<strong> <\/strong>\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0441\u0442\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0430\u043a <strong>const char* <\/strong>. \u041e\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0435 \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<pre><code class=\"cpp\">struct Simple { };  template &lt;typename T> std::string test() {   return __PRETTY_FUNCTION__; }  int main() {     std::cout &lt;&lt; test&lt;std::string>() &lt;&lt; std::endl;     std::cout &lt;&lt; test&lt;Simple>() &lt;&lt; std::endl; }  $> std::string test() [with T = std::__cxx11::basic_string&lt;char>; std::string = std::__cxx11::basic_string&lt;char>]    std::string test() [with T = Simple; std::string = std::__cxx11::basic_string&lt;char>]<\/code><\/pre>\n<p>C \u0442\u0430\u043a\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0430\u0440\u0441\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u0442 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 <strong>string<\/strong> \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438. \u041f\u043e\u0438\u0441\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u044f\u0436\u0435\u043b\u043e\u0432\u0430\u0442\u044b\u043c, \u0438 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043d\u043e \u043c\u044b \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0435\u043c.<\/p>\n<pre><code class=\"cpp\">struct Simple { };  template &lt;typename T> struct TypeNameHelper {     static std::string TypeName(void) {         const auto prefix   = std::string{\"[with T = \"};         const auto suffix   = std::string{\";\"};         const auto function = std::string{__PRETTY_FUNCTION__};              const auto start    = function.find(prefix) + prefix.size();         const auto end      = function.rfind(suffix);              const auto result   = function.substr(start, (end - start));              return result;     } };  template &lt;typename T> std::string TypeName(void) {     return TypeNameHelper&lt;T>::TypeName(); }  $> std::__cxx11::basic_string&lt;char> Simple<\/code><\/pre>\n<p>\u0415\u0449\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0443\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0435 \u0438\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u0441 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438, \u0438\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0441 -O2\/3 \u043a\u043b\u044e\u0447\u0430\u043c\u0438. \u041d\u0430 \u0441\u0431\u043e\u0440\u043a\u0435 \u0441 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430 \u043c\u0435\u0441\u0442\u0435 \u0441 -O3 (<a href=\"https:\/\/onlinegdb.com\/cjE1_rU9I\" rel=\"noopener noreferrer nofollow\">https:\/\/onlinegdb.com\/cjE1_rU9I<\/a>) \u0442\u043e\u0436\u0435.  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b. <\/p>\n<pre><code class=\"cpp\">enum test_enum { te_first, te_second, te_third, te_count }; int main() {    std::cout &lt;&lt; TypeName&lt;test_enum>() &lt;&lt; std::endl; }  $> test_enum<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0432 \u0432\u044b\u0432\u043e\u0434\u0435 \u0443\u0436\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u044d\u043d\u0430\u043c\u0430, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u043d\u0430\u043c\u0430, \u043c\u0430\u0433\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0435\u0449\u0435 \u043d\u0435\u0442, \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<pre><code class=\"cpp\">template &lt;typename T, T V> struct TypeNameHelper {     static const char* TypeName(void) {         static const size_t size = sizeof(__PRETTY_FUNCTION__);         static char typeName[size] = {};         memcpy(typeName, __PRETTY_FUNCTION__ , size - 1u);         return typeName;     } };  template &lt;typename T, T V> const char* TypeName(void) {     return TypeNameHelper&lt;T, V>::TypeName(); }  enum test_enum { te_first, te_second, te_third, te_count }; int main() {    std::cout &lt;&lt; TypeName&lt;test_enum, te_second>() &lt;&lt; std::endl; }  $> test_enum; T V = te_first<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0437\u0430\u0434\u0430\u0447\u0435 \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430, \u043a\u0440\u043e\u043c\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043e\u0431\u044b\u0447\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0435\u0451 \u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <strong>std::integer_sequence<\/strong> \u0438 fold expressions, \u0442\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u044d\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u044d\u043d\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u043d \u0441 &#171;\u0434\u044b\u0440\u043a\u0430\u043c\u0438&#187;.<\/p>\n<pre><code class=\"cpp\">template&lt;typename T, T... ints> void print_sequence(std::integer_sequence&lt;T, ints...> int_seq) {     std::cout &lt;&lt; \"The sequence of size \" &lt;&lt; int_seq.size() &lt;&lt; \": \";     ((std::cout &lt;&lt; ints &lt;&lt; ' '), ...);     std::cout &lt;&lt; '\\n'; }  int main() {      print_sequence(std::make_integer_sequence&lt;int, 20>{}); }  $> The sequence of size 20: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <\/code><\/pre>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u044f \u0432\u0441\u0435 \u043c\u044b\u0441\u043b\u0438 \u0432 \u043a\u0443\u0447\u0443 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043f\u0440\u043e\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<br \/>1. \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u044d\u043d\u0430\u043c \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0434\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0447\u0435\u0440\u0435\u0437 <strong>std::integer_sequence<\/strong>  <strong><br \/><\/strong>2. \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <strong>TypeName <\/strong>\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 <br \/>3. \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 { \u0438\u043c\u044f, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 } \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c<\/p>\n<p><strong>\u0420\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u043d\u0430\u043c\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 (\u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e)<\/strong><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u0442\u043e\u043c\u043b\u044f\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u043e\u0439, \u0431\u0443\u0434\u0443 \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u043f\u043e\u044f\u0441\u043d\u044f\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b. \u041a\u0430\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0443\u0431\u0435\u0434\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u044d\u043d\u0430\u043c \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0435 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043b\u0433\u043e \u0432 \u043f\u043b\u0430\u043d\u0435 \u043f\u0440\u043e\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u044f \u0434\u043e\u0431\u0438\u043b\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u044b, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043a\u043b\u0430\u043d\u0433\u0430 \u0438 \u0441\u0442\u0443\u0434\u0438\u0438, c gcc, \u0443\u0432\u044b, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. <\/p>\n<ul>\n<li>\n<p>count_values &#8212; \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0441\u0447\u0435\u0442 \u0447\u0438\u0441\u043b\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u044d\u043d\u0430\u043c\u0435<\/p>\n<\/li>\n<li>\n<p>make_tokens &#8212; \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u044d\u043d\u0430\u043c\u0430 \u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0438\u0445 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0430 { \u0438\u043c\u044f, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 }<\/p>\n<\/li>\n<li>\n<p>tokens &#8212; \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u044d\u043d\u0430\u043c\u0430, \u0438 \u0438\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>make_name &#8212; c \u043f\u043e\u043c\u043e\u0449\u044c\u044e __PRETTY_FUNCTION__ \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>token_holder &#8212; \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u0440\u044b\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">struct token {     const char * name;     s32 id; };  template&lt;typename enum_type, enum_type begin, enum_type end> struct token_holder {     constexpr static inline int count_values(enum_type type) {         return (type != end)             ? count_values((enum_type)(s32(type)+1))             : (s32(type)+1);     }      static constexpr u32 N = count_values(begin);     using tokens = std::array&lt;token, N+1>; \/\/ because have {0, 0} in last element      template&lt;typename e_enum_type, e_enum_type enum_value>     constexpr token make_name() {         return { enum_name&lt;e_enum_type, enum_value>().name(), enum_value };     }      template&lt;typename e_enum_type, u32... Indices>     constexpr tokens make_tokens_helper(std::integer_sequence&lt;u32, Indices...>) {         tokens ts = { make_name&lt;e_enum_type, (e_enum_type)Indices>()... };         ts[N] = {0, 0};         return ts;     }      template&lt;typename e_enum_type>     constexpr tokens make_tokens() {         return make_tokens_helper&lt;e_enum_type>( std::make_integer_sequence&lt;u32, N>{});     }       constexpr operator const token *() const { return values.unsafe_ptr(); }     constexpr token *data() const { return values.unsafe_ptr(); }     constexpr token_holder() : values{make_tokens&lt;enum_type>()} {}      tokens values; };<\/code><\/pre>\n<p><strong>\u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c<\/strong><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-340907","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/340907","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=340907"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/340907\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=340907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=340907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=340907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}