{"id":380826,"date":"2024-06-29T03:19:15","date_gmt":"2024-06-29T03:19:15","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=380826"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=380826","title":{"rendered":"<span>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043b\u0438\u0447\u043d\u043e\u0439 \u043c\u0430\u0433\u0438\u0438, \u043b\u0438\u0431\u043e \u043a\u0430\u043a \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/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>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u043d\u0435 \u0437\u0430\u0434\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u043a\u0443, \u0432 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0438 \u0432\u0441\u0451 \u0441\u0432\u0435\u043b\u043e\u0441\u044c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443: &#8212; \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u0432 \u043d\u0451\u043c \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b. \u041a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434\/\u044b \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0438 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435. \u0425\u043e\u0442\u0438\u043c \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0442\u044c &#8212; \u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u044b\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u043d\u044b, \u043f\u043e\u0441\u043b\u0435 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0437\u0430\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u0440\u0430\u0437\u0443 \u043f\u0440\u0435\u0434\u0432\u043e\u0441\u0445\u0438\u0449\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u0442\u0435\u043c\u0443 &#171;\u0430 \u0432\u043e\u0442 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e&#187;, &#171;\u0430 \u0432\u043e\u0442 \u043c\u043e\u0439 \u0433\u0446\u0446 5&#187;, &#171;\u0430 \u0432\u043e\u0442 \u0432 \u043c\u043e\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0441\u0438 \u0441 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438&#187; \u0438 \u043f\u0440\u043e\u0447\u0435\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0432\u0441\u0451(\u0447\u0442\u043e-\u043b\u0438\u0431\u043e \u0438\u0437) \u044d\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0432\u0430\u0441 &#8212; \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u0438\u0437 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u0434\u0435\u0441\u044c \u0432 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u043c\u043e\u0433\u0443\u0442 \u0442\u0435, \u043a\u0442\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442 \u0438 \u043a\u0430\u043a\u0438\u0435 \u0443 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f. <\/p>\n<p>\u041c\u043e\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e C++ \u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b \u0438 \u044f \u043d\u0438\u043a\u043e\u043c\u0443 \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0439 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043c\u0443, \u0447\u0435\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e \u044f. \u0410 \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0448\u0443 \u0432\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0438\u0437\u043b\u0438\u0448\u043d\u0435\u0433\u043e \u043d\u0430\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044f \u043c\u043d\u0435 \u0432\u0438\u0434\u0435\u043d\u0438\u0439 \u0432\u0430\u0448\u0438\u0445.<\/p>\n<p>\u0412\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u044f \u0433\u043e\u0432\u043e\u0440\u044e \u043e \u0421++, \u043b\u0438\u0431\u043e \u043e \u043a\u0430\u043a\u043e\u043c-\u043b\u0438\u0431\u043e \u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 &#8212; \u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u044e \u0432\u0432\u0438\u0434\u0443 gnu++, \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0435\u0433\u043e(gnu++) \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439. \u0415\u0441\u043b\u0438 \u044f \u0431\u0443\u0434\u0443 \u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435 &#8212; \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<p>\u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u0438 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043e\u0437\u043d\u0430\u043d\u0438\u044f \u0431\u044e\u0440\u043e\u043a\u0440\u0430\u0442\u0438\u0438, \u0440\u0430\u0437\u0432\u043e\u0434\u044f \u0437\u0434\u0435\u0441\u044c \u0440\u0435\u043b\u0438\u0433\u0438\u043e\u0437\u043d\u044b\u0435 \u0432\u043e\u0439\u043d\u044b. <\/p>\n<\/div>\n<\/details>\n<p>\u0424\u043e\u043a\u0443\u0441 \u0431\u0430\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445<\/p>\n<pre><code class=\"cpp\">struct a {      static inline auto x = 123;\/\/\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442   \/\/\u0434\u043e \u0441\u0442\u0430\u0440\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f main };  struct b {      static bool f() {     return true;   }   static inline auto x = f(); };<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c <code>static inline auto x = f()<\/code> &#8212; \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u041b\u044e\u0431\u044b\u0435 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u044b, \u0434\u0430\u0436\u0435 \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0442\u0430\u043c <code>return true<\/code> &#8212; \u044d\u0442\u043e \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u044f\u0437\u044b\u043a\u0430.<\/p>\n<p>\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430:<\/p>\n<pre><code class=\"cpp\">#include&lt;cstdio>  struct c {   static bool f() {     fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__);     return true;   }   static inline auto x = f(); };   int main() {   fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__); }<\/code><\/pre>\n<p>\u0432\u044b\u0432\u0435\u0434\u0435\u0442: <\/p>\n<pre><code>static bool c::f() int main()<\/code><\/pre>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f &#8212; \u044d\u0442\u043e<\/p>\n<pre><code class=\"cpp\">template&lt;typename> struct plugin {      static bool f() {     fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__);     return true;   }   static inline auto x = f(); };  struct my_plugin: plugin&lt;my_plugin> {};\/\/\u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 &#8212; \u043b\u044e\u0431\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u043d\u043e\u0433\u043e\/\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043b\u0435\u043d\u0438\u0432\u043e, \u0442.\u0435. \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438.<\/p>\n<pre><code class=\"cpp\">template&lt;typename T> struct test {   auto f() {     T x = \"\";   } };  test&lt;int> _;\/\/\u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435 \u043f\u043b\u0430\u0442\u0438\u0442\u044c \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c<\/p>\n<p>\u0432\u043e\u0437\u044c\u043c\u0451\u043c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">template&lt;auto x> struct integral_constant {   constexpr operator auto() const { return x; }      template&lt;auto y> constexpr integral_constant&lt;x % y> operator%(integral_constant&lt;y>) const { return {};}   template&lt;auto y> constexpr integral_constant&lt;x + y> operator+(integral_constant&lt;y>) const { return {};} };<\/code><\/pre>\n<p><code>static_assert(integral_constant&lt;1.>{} + integral_constant&lt;2.>{} == 3.);<\/code> &#8212; \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0442\u043e,  \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 %<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432 <code>integral_constant \u0435\u0441\u0442\u044c operator%, \u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0443\u0435\u043c \u043c\u044b \u0435\u0451(integral_constant) double \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 % \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 - \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/code><\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c:<\/p>\n<pre><code class=\"cpp\">static_assert(integral_constant&lt;3>{} % integral_constant&lt;2>{} == 1);   constexpr auto test_mod(auto a, auto b) {   return requires {     a % b;   }; }   static_assert(!test_mod(integral_constant&lt;1.>{}, integral_constant&lt;2.>{})); static_assert(test_mod(integral_constant&lt;1>{}, integral_constant&lt;2>{}));<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 &#8212; sfinae. \u0415\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0442\u0430\u043a\u043e\u0433\u043e \u0436\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u0443 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0436\u0435 double &#8212; \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0432\u044b\u043d\u0435\u0441 \u0438\u0445<code>\u0442\u0430\u043a: integral_constant&lt;x % y> - \u043c\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0435\u0441\u043b\u0438 \u043c\u0435\u0436\u0434\u0443 x \u0438 y \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e %. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u044d\u0442\u043e \u0432 \u0442\u0435\u043b\u0435 - sfinae \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0431\u0438\u0432\u0430\u0442\u044c\u0441\u044f.<\/code><\/p>\n<p><code>\u042d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u0437 \u0444\u0430\u043a\u0442\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043b\u0430. +\/- \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043a\u043e\u0433\u0434\u0430-\u0442\u043e, \u043d\u043e \u043d\u0435 \u0441\u0435\u0439\u0447\u0430\u0441. \u0417\u0434\u0435\u0441\u044c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f \u0441 \u043d\u0430\u0441\u043b\u0435\u0434\u0438\u0435\u043c.<\/code><\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432\u044b\u0448\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e &#8212; \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435 \u0432\u043d\u0435 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u043e\u0433\u043e\/\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<pre><code class=\"cpp\">struct my_plugin2: plugin&lt;my_plugin2> {   static inline auto x = plugin::x;\/\/\u0441\u0430\u0439\u0434-\u044d\u0444\u0444\u0435\u043a\u0442\u043e\u043c \u044d\u0442\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432 plugin&lt;my_plugin2>::f.   \/\/\u0422\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u043d\u043e };<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043b\u0438\u0448\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435<\/p>\n<pre><code class=\"cpp\">template&lt;auto tag> struct registry {   static auto push() {     fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__);     return true;   }   static inline auto x = push(); };  #undef NDEBUG #include&lt;cassert>  template&lt;typename = void> struct object {   void a() {     assert(registry&lt;&amp;object::a>::x);   }   void b() {     assert(registry&lt;&amp;object::b>::x);   } };  void test_registry() {   object o;   o.a();\/\/static auto registry&lt;&lt;anonymous> >::push() [with auto &lt;anonymous> = &amp;object&lt;void>::a]   \/\/o.b();\/\/static auto registry&lt;&lt;anonymous> >::push() [with auto &lt;anonymous> = &amp;object&lt;void>::b] }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c static_assert, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 constexpr \u043d\u043e \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043a\u0430\u043a constexpr<\/p>\n<pre><code class=\"cpp\">constexpr integral_constant&lt;true> true_;  template&lt;auto tag> struct registryv2 {   static auto push() {     fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__);     return true_;   }   static inline auto x = push(); };  template&lt;typename = void> struct objectv2 {   void a() {     static_assert(registryv2&lt;&amp;objectv2::a>::x);   }   void b() {     static_assert(registryv2&lt;&amp;objectv2::b>::x);   } };  void test_registryv2() {   objectv2 o;   o.a();\/\/static auto registryv2&lt;&lt;anonymous> >::push() [with auto &lt;anonymous> = &amp;objectv2&lt;void>::a] \/\/   o.b();\/\/static auto registryv2&lt;&lt;anonymous> >::push() [with auto &lt;anonymous> = &amp;objectv2&lt;void>::b] }  template&lt;typename T = void> void f() {   static_assert(registryv2&lt;&amp;f&lt;T>>::x); }  void test_f() { \/\/   f();\/\/static auto registryv2&lt;tag>::push() [with auto tag = f&lt;>] }     int main() {   fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__); }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u0441\u0443\u0432\u0430\u0442\u044c \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u0448\u0430\u0431\u043b\u043e\u043d \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"cpp\">using private_unique_type = decltype([]{});  template&lt;typename T = private_unique_type> void f2() {   static_assert(__is_same(T, private_unique_type));   static_assert(registryv2&lt;&amp;f2&lt;T>>::x); }   void test_f2() { \/\/   f2(); }<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/1Wrn1PMTW\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/581200\/\"> https:\/\/habr.com\/ru\/articles\/581200\/<\/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>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u043d\u0435 \u0437\u0430\u0434\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u043a\u0443, \u0432 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0438 \u0432\u0441\u0451 \u0441\u0432\u0435\u043b\u043e\u0441\u044c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443: &#8212; \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u0432 \u043d\u0451\u043c \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b. \u041a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434\/\u044b \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0438 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435. \u0425\u043e\u0442\u0438\u043c \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0442\u044c &#8212; \u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u044b\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u043d\u044b, \u043f\u043e\u0441\u043b\u0435 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0437\u0430\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u0440\u0430\u0437\u0443 \u043f\u0440\u0435\u0434\u0432\u043e\u0441\u0445\u0438\u0449\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u0442\u0435\u043c\u0443 &#171;\u0430 \u0432\u043e\u0442 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e&#187;, &#171;\u0430 \u0432\u043e\u0442 \u043c\u043e\u0439 \u0433\u0446\u0446 5&#187;, &#171;\u0430 \u0432\u043e\u0442 \u0432 \u043c\u043e\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0441\u0438 \u0441 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438&#187; \u0438 \u043f\u0440\u043e\u0447\u0435\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0432\u0441\u0451(\u0447\u0442\u043e-\u043b\u0438\u0431\u043e \u0438\u0437) \u044d\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0432\u0430\u0441 &#8212; \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u0438\u0437 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u0434\u0435\u0441\u044c \u0432 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u043c\u043e\u0433\u0443\u0442 \u0442\u0435, \u043a\u0442\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442 \u0438 \u043a\u0430\u043a\u0438\u0435 \u0443 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f. <\/p>\n<p>\u041c\u043e\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e C++ \u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b \u0438 \u044f \u043d\u0438\u043a\u043e\u043c\u0443 \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0439 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043c\u0443, \u0447\u0435\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e \u044f. \u0410 \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0448\u0443 \u0432\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0438\u0437\u043b\u0438\u0448\u043d\u0435\u0433\u043e \u043d\u0430\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044f \u043c\u043d\u0435 \u0432\u0438\u0434\u0435\u043d\u0438\u0439 \u0432\u0430\u0448\u0438\u0445.<\/p>\n<p>\u0412\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u044f \u0433\u043e\u0432\u043e\u0440\u044e \u043e \u0421++, \u043b\u0438\u0431\u043e \u043e \u043a\u0430\u043a\u043e\u043c-\u043b\u0438\u0431\u043e \u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 &#8212; \u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u044e \u0432\u0432\u0438\u0434\u0443 gnu++, \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0435\u0433\u043e(gnu++) \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439. \u0415\u0441\u043b\u0438 \u044f \u0431\u0443\u0434\u0443 \u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435 &#8212; \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<p>\u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u0438 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043e\u0437\u043d\u0430\u043d\u0438\u044f \u0431\u044e\u0440\u043e\u043a\u0440\u0430\u0442\u0438\u0438, \u0440\u0430\u0437\u0432\u043e\u0434\u044f \u0437\u0434\u0435\u0441\u044c \u0440\u0435\u043b\u0438\u0433\u0438\u043e\u0437\u043d\u044b\u0435 \u0432\u043e\u0439\u043d\u044b. <\/p>\n<\/div>\n<\/details>\n<p>\u0424\u043e\u043a\u0443\u0441 \u0431\u0430\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445<\/p>\n<pre><code class=\"cpp\">struct a {      static inline auto x = 123;\/\/\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442   \/\/\u0434\u043e \u0441\u0442\u0430\u0440\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f main };  struct b {      static bool f() {     return true;   }   static inline auto x = f(); };<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c <code>static inline auto x = f()<\/code> &#8212; \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u041b\u044e\u0431\u044b\u0435 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u044b, \u0434\u0430\u0436\u0435 \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0442\u0430\u043c <code>return true<\/code> &#8212; \u044d\u0442\u043e \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u044f\u0437\u044b\u043a\u0430.<\/p>\n<p>\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430:<\/p>\n<pre><code class=\"cpp\">#include&lt;cstdio>  struct c {   static bool f() {     fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__);     return true;   }   static inline auto x = f(); };   int main() {   fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__); }<\/code><\/pre>\n<p>\u0432\u044b\u0432\u0435\u0434\u0435\u0442: <\/p>\n<pre><code>static bool c::f() int main()<\/code><\/pre>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f &#8212; \u044d\u0442\u043e<\/p>\n<pre><code class=\"cpp\">template&lt;typename> struct plugin {      static bool f() {     fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__);     return true;   }   static inline auto x = f(); };  struct my_plugin: plugin&lt;my_plugin> {};\/\/\u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 &#8212; \u043b\u044e\u0431\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u043d\u043e\u0433\u043e\/\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043b\u0435\u043d\u0438\u0432\u043e, \u0442.\u0435. \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438.<\/p>\n<pre><code class=\"cpp\">template&lt;typename T> struct test {   auto f() {     T x = \"\";   } };  test&lt;int> _;\/\/\u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435 \u043f\u043b\u0430\u0442\u0438\u0442\u044c \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c<\/p>\n<p>\u0432\u043e\u0437\u044c\u043c\u0451\u043c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">template&lt;auto x> struct integral_constant {   constexpr operator auto() const { return x; }      template&lt;auto y> constexpr integral_constant&lt;x % y> operator%(integral_constant&lt;y>) const { return {};}   template&lt;auto y> constexpr integral_constant&lt;x + y> operator+(integral_constant&lt;y>) const { return {};} };<\/code><\/pre>\n<p><code>static_assert(integral_constant&lt;1.>{} + integral_constant&lt;2.>{} == 3.);<\/code> &#8212; \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0442\u043e,  \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 %<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432 <code>integral_constant \u0435\u0441\u0442\u044c operator%, \u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0443\u0435\u043c \u043c\u044b \u0435\u0451(integral_constant) double \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 % \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 - \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/code><\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c:<\/p>\n<pre><code class=\"cpp\">static_assert(integral_constant&lt;3>{} % integral_constant&lt;2>{} == 1);   constexpr auto test_mod(auto a, auto b) {   return requires {     a % b;   }; }   static_assert(!test_mod(integral_constant&lt;1.>{}, integral_constant&lt;2.>{})); static_assert(test_mod(integral_constant&lt;1>{}, integral_constant&lt;2>{}));<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 &#8212; sfinae. \u0415\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0442\u0430\u043a\u043e\u0433\u043e \u0436\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u0443 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0436\u0435 double &#8212; \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0432\u044b\u043d\u0435\u0441 \u0438\u0445<code>\u0442\u0430\u043a: integral_constant&lt;x % y> - \u043c\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0435\u0441\u043b\u0438 \u043c\u0435\u0436\u0434\u0443 x \u0438 y \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e %. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u044d\u0442\u043e \u0432 \u0442\u0435\u043b\u0435 - sfinae \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0431\u0438\u0432\u0430\u0442\u044c\u0441\u044f.<\/code><\/p>\n<p><code>\u042d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u0437 \u0444\u0430\u043a\u0442\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043b\u0430. +\/- \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043a\u043e\u0433\u0434\u0430-\u0442\u043e, \u043d\u043e \u043d\u0435 \u0441\u0435\u0439\u0447\u0430\u0441. \u0417\u0434\u0435\u0441\u044c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f \u0441 \u043d\u0430\u0441\u043b\u0435\u0434\u0438\u0435\u043c.<\/code><\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432\u044b\u0448\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e &#8212; \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435 \u0432\u043d\u0435 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u043e\u0433\u043e\/\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<pre><code class=\"cpp\">struct my_plugin2: plugin&lt;my_plugin2> {   static inline auto x = plugin::x;\/\/\u0441\u0430\u0439\u0434-\u044d\u0444\u0444\u0435\u043a\u0442\u043e\u043c \u044d\u0442\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432 plugin&lt;my_plugin2>::f.   \/\/\u0422\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u043d\u043e };<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043b\u0438\u0448\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435<\/p>\n<pre><code class=\"cpp\">template&lt;auto tag> struct registry {   static auto push() {     fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__);     return true;   }   static inline auto x = push(); };  #undef NDEBUG #include&lt;cassert>  template&lt;typename = void> struct object {   void a() {     assert(registry&lt;&amp;object::a>::x);   }   void b() {     assert(registry&lt;&amp;object::b>::x);   } };  void test_registry() {   object o;   o.a();\/\/static auto registry&lt;&lt;anonymous> >::push() [with auto &lt;anonymous> = &amp;object&lt;void>::a]   \/\/o.b();\/\/static auto registry&lt;&lt;anonymous> >::push() [with auto &lt;anonymous> = &amp;object&lt;void>::b] }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c static_assert, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 constexpr \u043d\u043e \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043a\u0430\u043a constexpr<\/p>\n<pre><code class=\"cpp\">constexpr integral_constant&lt;true> true_;  template&lt;auto tag> struct registryv2 {   static auto push() {     fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__);     return true_;   }   static inline auto x = push(); };  template&lt;typename = void> struct objectv2 {   void a() {     static_assert(registryv2&lt;&amp;objectv2::a>::x);   }   void b() {     static_assert(registryv2&lt;&amp;objectv2::b>::x);   } };  void test_registryv2() {   objectv2 o;   o.a();\/\/static auto registryv2&lt;&lt;anonymous> >::push() [with auto &lt;anonymous> = &amp;objectv2&lt;void>::a] \/\/   o.b();\/\/static auto registryv2&lt;&lt;anonymous> >::push() [with auto &lt;anonymous> = &amp;objectv2&lt;void>::b] }  template&lt;typename T = void> void f() {   static_assert(registryv2&lt;&amp;f&lt;T>>::x); }  void test_f() { \/\/   f();\/\/static auto registryv2&lt;tag>::push() [with auto tag = f&lt;>] }     int main() {   fprintf(stderr, \"%s\\n\", __PRETTY_FUNCTION__); }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u0441\u0443\u0432\u0430\u0442\u044c \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u0448\u0430\u0431\u043b\u043e\u043d \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"cpp\">using private_unique_type = decltype([]{});  template&lt;typename T = private_unique_type> void f2() {   static_assert(__is_same(T, private_unique_type));   static_assert(registryv2&lt;&amp;f2&lt;T>>::x); }   void test_f2() { \/\/   f2(); }<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/1Wrn1PMTW\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/581200\/\"> https:\/\/habr.com\/ru\/articles\/581200\/<\/a><br \/><\/br><\/br><\/p>\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-380826","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/380826","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=380826"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/380826\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=380826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=380826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=380826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}