{"id":244573,"date":"2014-12-01T04:33:02","date_gmt":"2014-12-01T00:33:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=244573"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=244573","title":{"rendered":"<span class=\"post_title\">Eggs.Variant \u2014 \u0427\u0430\u0441\u0442\u044c I<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       \u041d\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u043c\u0435\u043d\u044f \u0441\u043f\u043e\u0434\u0432\u0438\u0433 <a href=\"\/post\/244497\/#comment_8153531\">\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/a> \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <b><a href=\"http:\/\/habrahabr.ru\/users\/encyclopedist\/\" class=\"user_link\">encyclopedist<\/a><\/b> \u043a \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"\/post\/244497\/\">\u00ab\u0424\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0431\u0435\u0437 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0432 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438\u00bb<\/a>. \u0421\u0442\u0430\u0442\u044c\u044f \u043c\u0435\u043d\u044f \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0430, \u043d\u043e \u0431\u0435\u0433\u043b\u043e\u0435 <i>\u0433\u0443\u0433\u043b\u0435\u043d\u0438\u0435<\/i> \u043d\u0435 \u0432\u044b\u044f\u0432\u0438\u043b\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430. \u00ab\u041d\u0435\u043f\u043e\u0440\u044f\u0434\u043e\u043a.\u00bb\u00a0\u2014 \u043f\u043e\u0434\u0443\u043c\u0430\u043b \u044f\u00a0\u2014 \u00ab\u0422\u0430\u043a\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e \u0421++ \u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u0430 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a. \u041d\u0430\u0434\u043e \u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c.\u00bb<\/p>\n<p>  <b>\u041e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/b>  <\/p>\n<ol>\n<li><a href=\"#introduction\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/a><\/li>\n<li><a href=\"#design\">\u041f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><\/li>\n<li> <a href=\"#implementation\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/a><br \/> \n<ul>\n<li><a href=\"#trivially-copyable\">\u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b<\/a><\/li>\n<li><a href=\"#trivially-destructible\">\u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0443\u0448\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b<\/a><\/li>\n<\/ul>\n<p>   <\/li>\n<li><a href=\"#what-lies-ahead\">\u041e \u0447\u0451\u043c \u0435\u0449\u0451 \u043d\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043e<\/a><\/li>\n<\/ol>\n<p>  \u0420\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u044f \u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 <a href=\"https:\/\/github.com\/eggs-cpp\/variant\">Eggs.Variant<\/a>\u00a0\u2014 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u043c \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c <abbr title=\"discriminated union\">\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438<\/abbr> \u043d\u0430 <strong>C++11\/14<\/strong>.<\/p>\n<h1><a name=\"introduction\"><\/a>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h1>\n<p>  <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/union\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/a>\u00a0\u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0432\u043e\u0438\u0445 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432. \u041e\u043d \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u0442\u0430, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0434\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0438\u0437 \u0435\u0433\u043e \u0447\u043b\u0435\u043d\u043e\u0432.  <\/p>\n<blockquote><p> <strong>9 [class]\/5<\/strong> \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u00a0\u2014 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0439 \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <code>union<\/code>; \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0432\u043e\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432 (9.5). [&#8230;]<br \/>   <strong>9.5 [class.union]\/1<\/strong> \u0412 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c, \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0435\u0433\u043e \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432. [&#8230;] \u0420\u0430\u0437\u043c\u0435\u0440 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u0435\u043d \u0434\u043b\u044f \u0432\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0438\u0437 \u0435\u0433\u043e \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0447\u043b\u0435\u043d \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a, \u0441\u043b\u043e\u0432\u043d\u043e \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0447\u043b\u0435\u043d\u043e\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0412\u0441\u0435 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0447\u043b\u0435\u043d\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0430\u0434\u0440\u0435\u0441.  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>9 [class]\/5<\/strong> A union is a class defined with the class-key union; it holds at most one data member at a time (9.5). [&#8230;]<br \/>   <strong>9.5 [class.union]\/1<\/strong> In a union, at most one of the non-static data members can be active at any time, that is, the value of at most one of the non-static data members can be stored in a union at any time. [&#8230;] The size of a union is sufficient to contain the largest of its non-static data members. Each non-static data member is allocated as if it were the sole member of a struct. All non-static data members of a union object have the same address.   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0412 <strong>C++98<\/strong> \u0447\u043b\u0435\u043d\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0438\u0445 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 <abbr title=\"storage\">\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430<\/abbr> \u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u043b\u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0438.  <\/p>\n<blockquote><p> <strong>3.8 [basic.life]\/1<\/strong> [&#8230;] \u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0438\u043f\u0430 <code>T<\/code> \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430:   <\/p>\n<ul>\n<li>\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0434\u043b\u044f \u0442\u0438\u043f\u0430 <code>T<\/code> \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0438<\/li>\n<li>\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430.<\/li>\n<\/ul>\n<p>   \u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0438\u043f\u0430 <code>T<\/code> \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430:   <\/p>\n<ul>\n<li>\u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u0435\u0441\u043b\u0438 <code>T<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0438\u043f\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c (12.4), \u0438\u043b\u0438<\/li>\n<li>\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0438\u043b\u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u043e.<\/li>\n<\/ul>\n<p>  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>3.8 [basic.life]\/1<\/strong> [&#8230;] The lifetime of an object of type <code>T<\/code> begins when:   <\/p>\n<ul>\n<li>storage with the proper alignment and size for type <code>T<\/code> is obtained, and<\/li>\n<li>if the object has non-trivial initialization, its initialization is complete.<\/li>\n<\/ul>\n<p>   The lifetime of an object of type <code>T<\/code> ends when:   <\/p>\n<ul>\n<li>if <code>T<\/code> is a class type with a non-trivial destructor (12.4), the destructor call starts, or<\/li>\n<li>the storage which the object occupies is reused or released.<\/li>\n<\/ul>\n<p>   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u042d\u0442\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0447\u043b\u0435\u043d \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u00a0\u2014 \u0447\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u0443\u0435\u0442\u0441\u044f \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441 \u0431\u0443\u043a\u0432\u043e\u0439, \u0442\u043e \u0441 \u0434\u0443\u0445\u043e\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430.<br \/>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a\u043e\u0439 \u0435\u0433\u043e \u0447\u043b\u0435\u043d\u00a0\u2014 \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c\u00a0\u2014 \u0430\u043a\u0442\u0438\u0432\u0435\u043d, \u0442\u0430\u043a \u0447\u0442\u043e \u0435\u0433\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0435\u0437 \u0437\u043d\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0447\u043b\u0435\u043d\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438, \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 <abbr title=\"underlying\">\u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u0432 \u043e\u0441\u043d\u043e\u0432\u0435<\/abbr> \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u0430\u0439\u0442\u043e\u0432 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0445 \u043e\u0442 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430.  <\/p>\n<blockquote><p> <strong>9.5 [class.union]\/1<\/strong> [&#8230;] \u041e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c (12.1), \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (12.8), \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c (12.4) \u0438\u043b\u0438 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043f\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f (13.5.3, 12.8) \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0447\u043b\u0435\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043b\u0438\u0431\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438. [&#8230;]  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>9.5 [class.union]\/1<\/strong> [&#8230;] An object of a class with a non-trivial constructor (12.1), a non-trivial copy constructor (12.8), a non-trivial destructor (12.4), or a non-trivial copy assignment operator (13.5.3, 12.8) cannot be a member of a union, nor can an array of such objects. [&#8230;]   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0412 <strong>C++11<\/strong> \u044d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u043e; \u0447\u043b\u0435\u043d\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u041f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0447\u043b\u0435\u043d\u0430\u043c\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u044f\u0432\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <abbr title=\"placement new\">\u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e\u0449\u0435\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>new<\/code><\/abbr> \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430.  <\/p>\n<blockquote><p> <strong>9.5 [class.union]\/4<\/strong> [\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u044f\u0432\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0438 \u043e\u0434\u0438\u043d \u044f\u0432\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e\u0449\u0435\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>new<\/code> \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f.\u00a0\u2014\u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u044f] [\u041f\u0440\u0438\u043c\u0435\u0440: \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442 <code>u<\/code> \u0442\u0438\u043f\u0430 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f <code>U<\/code>, \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0447\u043b\u0435\u043d\u044b <code>m<\/code> \u0442\u0438\u043f\u0430 <code>M<\/code> \u0438 <code>n<\/code> \u0442\u0438\u043f\u0430 <code>N<\/code>. \u0415\u0441\u043b\u0438 <code>M<\/code> \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0430 <code>N<\/code> \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0435\u0441\u043b\u0438 \u0432 \u043d\u0438\u0445 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b \u0438\u043b\u0438 \u043e\u043d\u0438 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438), \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0447\u043b\u0435\u043d <code>u<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0451\u043d \u0441 <code>m<\/code> \u043d\u0430 <code>n<\/code> \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e\u0449\u0435\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>new<\/code>:  <\/p>\n<pre><code class=\"cpp\">u.m.~M(); new (&amp;u.n) N; <\/code><\/pre>\n<p>   \u2014\u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u0438\u043c\u0435\u0440\u0430]  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>9.5 [class.union]\/4<\/strong> [Note: In general, one must use explicit destructor calls and placement new operators to change the active member of a union.\u00a0\u2014end note] [Example: Consider an object <code>u<\/code> of a union type <code>U<\/code> having non-static data members <code>m<\/code> of type <code>M<\/code> and <code>n<\/code> of type <code>N<\/code>. If <code>M<\/code> has a non-trivial destructor and <code>N<\/code> has a non-trivial constructor (for instance, if they declare or inherit virtual functions), the active member of <code>u<\/code> can be safely switched from <code>m<\/code> to <code>n<\/code> using the destructor and placement new operator as follows:  <\/p>\n<pre><code class=\"cpp\">u.m.~M(); new (&amp;u.n) N; <\/code><\/pre>\n<p>   \u2014end example]   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0415\u0441\u043b\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u0447\u043b\u0435\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u0447\u043b\u0435\u043d\u043e\u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u0447\u043b\u0435\u043d \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u044f\u0432\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u0430\u044f, \u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0451 \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0441\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c.  <\/p>\n<blockquote><p> <strong>9.5 [class.union]\/2<\/strong> [\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0435\u0441\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0447\u043b\u0435\u043d \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e (12.1), \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (12.8), \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f (12.8), \u043a\u043e\u043f\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u0441\u0432\u0430\u043d\u0438\u0432\u0430\u043d\u0438\u044f (12.8), \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044e\u0449\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f (12.8) \u0438\u043b\u0438 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 (12.4), \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u0447\u043b\u0435\u043d \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0438\u043b\u0438 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u044f\u0432\u043d\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0430 (8.4.3) \u0438\u0437 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.\u00a0\u2014\u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u044f]<br \/>   <strong>9.5 [class.union]\/3<\/strong> [\u041f\u0440\u0438\u043c\u0435\u0440: \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"cpp\">union U {   int i;   float f;   std::string s; }; <\/code><\/pre>\n<p>   \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0438\u043f <code>std::string<\/code> (21.3) \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0432\u0441\u0435\u0445 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u0447\u043b\u0435\u043d\u043e\u0432, \u0443 \u0442\u0438\u043f\u0430 <code>U<\/code> \u0431\u0443\u0434\u0443\u0442 \u043d\u0435\u044f\u0432\u043d\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\/\u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f, \u043a\u043e\u043f\u0438\u0440\u0443\u044e\u0449\u0438\u0439\/\u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044e\u0449\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440. \u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>U<\/code> \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u0447\u043b\u0435\u043d\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c.\u00a0\u2014\u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u0438\u043c\u0435\u0440\u0430]  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>9.5 [class.union]\/2<\/strong> [Note: If any non-static data member of a union has a non-trivial default constructor (12.1), copy constructor (12.8), move constructor (12.8), copy assignment operator (12.8), move assignment operator (12.8), or destructor (12.4), the corresponding member function of the union must be user-provided or it will be implicitly deleted (8.4.3) for the union.\u00a0\u2014end note]<br \/>   <strong>9.5 [class.union]\/3<\/strong> [Example: Consider the following union:  <\/p>\n<pre><code class=\"cpp\">union U {   int i;   float f;   std::string s; }; <\/code><\/pre>\n<p>   Since <code>std::string<\/code> (21.3) declares non-trivial versions of all of the special member functions, <code>U<\/code> will have an implicitly deleted default constructor, copy\/move constructor, copy\/move assignment operator, and destructor. To use <code>U<\/code>, some or all of these member functions must be user-provided.\u00a0\u2014end example]   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u042d\u0442\u0438 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b\u00a0\u2014 \u0441 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435\u043c \u0438\u0445 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438\u00a0\u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0437\u043d\u0430\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u043e\u0439 \u0447\u043b\u0435\u043d \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435. \u0420\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0435 <em>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/em>\u00a0\u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441, \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 <abbr title=\"self-aware\">\u0437\u043d\u0430\u043d\u0438\u0435\u043c \u043e \u0441\u0435\u0431\u0435<\/abbr>, \u0442\u043e \u0435\u0441\u0442\u044c, \u043e\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0447\u043b\u0435\u043d\u00a0\u2014 \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0441\u0442\u044c\u00a0\u2014 \u0441\u0435\u0439\u0447\u0430\u0441 \u0430\u043a\u0442\u0438\u0432\u0435\u043d. \u0420\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0435 <em>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/em> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u044b, \u043d\u0435\u0432\u0430\u0436\u043d\u043e, \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u043d\u0438 \u0438\u043b\u0438 \u043d\u0435\u0442.<br \/>  \u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>eggs::variant&lt;Ts...&gt;<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c <em>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u043c<\/em> \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0442\u0438\u043f\u0430\u043c\u0438 <code>Ts<\/code>. \u041e\u043d \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430 \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u044b \u0441 \u0438\u0445 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u043e\u0439:  <\/p>\n<pre><code class=\"cpp\">eggs::variants&lt;N, M&gt; u; \/\/ u \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430 u = M{}; \/\/ u \u0438\u043c\u0435\u0435\u0442 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0447\u043b\u0435\u043d \u0442\u0438\u043f\u0430 M u = N{}; \/\/ u \u0438\u043c\u0435\u0435\u0442 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0447\u043b\u0435\u043d \u0442\u0438\u043f\u0430 N, \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0447\u043b\u0435\u043d \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d  \/\/ \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u044b using U = eggs::variants&lt;int, float, std::string&gt;; <\/code><\/pre>\n<h1><a name=\"design\"><\/a>\u041f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h1>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u044c\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0433\u043e <em>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/em> \u0431\u0435\u0437 \u0443\u0449\u0435\u0440\u0431\u0430 \u0434\u043b\u044f \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0422\u043e \u0435\u0441\u0442\u044c, \u0443 \u043d\u0435\u0433\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043b\u0438\u0431\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430:  <\/p>\n<pre><code class=\"cpp\">struct U {   union { T0 m0; ...; TN mN; };   std::size_t which; } u; <\/code><\/pre>\n<p>  \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u044d\u0442\u0438\u043c:  <\/p>\n<pre><code class=\"cpp\">using V = eggs::variant&lt;T0, ..., TN&gt;; V v; <\/code><\/pre>\n<p>  \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438:  <\/p>\n<ul>\n<li>\u0420\u0430\u0437\u043c\u0435\u0440 \u0442\u0438\u043f\u0430 <code>V<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u0438\u043f\u0430 <code>U<\/code>. \u041b\u044e\u0431\u043e\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0447\u043b\u0435\u043d <code>v<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 <code>V<\/code>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b\u0440\u043e\u0432\u043d\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f \u0442\u0438\u043f\u043e\u0432 <code>T0, ... TN<\/code>; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f.<\/li>\n<li>\u0427\u0451\u0442\u043a\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0430\u044f \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 <code>u<\/code> \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u0431\u044b\u0442\u044c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u043e\u0439 <code>v<\/code>. \u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0447\u043b\u0435\u043d <code>u<\/code>, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442\u044c\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <code>v<\/code>.<\/li>\n<li>\u0422\u0438\u043f\u043e\u043c <code>V<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u044b \u0441 \u0438\u0445 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u043e\u0439.<\/li>\n<\/ul>\n<p>  \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/experimental\/optional\"><code>std::experimental::optional&lt;T&gt;<\/code><\/a>, \u043a\u0430\u043a \u043e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0432 <a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2014\/n4082.pdf\"><abbr title=\"Library Fundamentals TS\">\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/abbr><\/a>. \u041a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c <code>optional&lt;T&gt;<\/code> \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0433\u043e <em>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/em> \u0442\u0438\u043f\u043e\u0432 <code>nullopt_t<\/code> \u0438 <code>T<\/code>. \u041f\u0440\u043e\u0435\u043a\u0442\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u0435 \u0434\u043b\u044f <code>optional&lt;T&gt;<\/code>, \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043d\u0430 <code>variant&lt;Ts...&gt;<\/code>, \u0447\u044c\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 <code>nullvariant_t<\/code> \u0438 \u0442\u0435\u0445, \u0447\u0442\u043e \u0441\u043a\u0440\u044b\u0442\u044b \u0437\u0430 <code>Ts<\/code>. \u0421\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u0432\u0441\u0435\u0445 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u0447\u043b\u0435\u043d\u043e\u0432 \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430\u00a0\u2014 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u00a0\u2014 \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f \u043e\u0442 <code>optional&lt;T&gt;<\/code>.<br \/>  \u0414\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u0447\u043b\u0435\u043d\u0443 \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0438\u0437\u0430\u0439\u043d\u0435 <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/utility\/functional\/function\"><code>std::function<\/code><\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0446\u0435\u043b\u044c, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c \u0446\u0435\u043b\u0438\u00a0\u2014 \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 <code>dynamic_cast<\/code> \u0434\u043b\u044f \u0431\u0435\u0434\u043d\u044b\u0445. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043e\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0447\u043b\u0435\u043d (\u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0441\u0442\u044c), \u0447\u0442\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<br \/>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 <a href=\"http:\/\/eggs-cpp.github.io\/variant\/reference.html\"><code>std::tuple<\/code><\/a>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0438\u043b\u0438 \u043f\u043e \u0442\u0438\u043f\u0443\u00a0\u2014 \u0445\u043e\u0442\u044f \u0438 \u0441 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0439 \u0441\u0435\u043c\u0430\u043d\u0442\u043a\u043e\u0439, \u0431\u043e\u043b\u0435\u0435 \u0431\u043b\u0438\u0437\u043a\u043e\u0439 \u043a \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044e \u0442\u0438\u043f\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<br \/>  \u0421\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0439\u0434\u0435\u043d\u0430 <a href=\"http:\/\/eggs-cpp.github.io\/variant\/reference.html\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h1><a name=\"implementation\"><\/a>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h1>\n<p>  \u041f\u0440\u044f\u043c\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>variant&lt;Ts&gt;<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 \u0431\u044b \u043d\u0438\u0436\u0435\u043b\u0435\u0436\u0430\u0449\u0435\u0435 <abbr title=\"relaxed union\">\u0440\u0430\u0441\u0441\u043b\u0430\u0431\u043b\u0435\u043d\u043d\u043e\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/abbr>:  <\/p>\n<pre><code class=\"cpp\">template &lt;typename ...Ts&gt; union storage {   nullvariant_t nullvariant;   Ts... members; }; <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 <strong>C++<\/strong>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u043a\u0440\u044b\u0442 \u0432 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435\u00a0\u2014 \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u0430 \u0447\u043b\u0435\u043d\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043d\u0438\u0436\u0435\u043b\u0435\u0436\u0430\u0449\u0435\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434:  <\/p>\n<pre><code class=\"cpp\">template &lt;typename ...Ts&gt; union storage;  template &lt;typename T, typename ...Ts&gt; union storage&lt;T, Ts...&gt; {   nullvariant_t nullvariant;   T head;   storage&lt;Ts...&gt; tail; };  template &lt;&gt; union storage&lt;&gt; {   nullvariant_t nullvariant; }; <\/code><\/pre>\n<p>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0442\u043e, \u0447\u0442\u043e \u043b\u044e\u0431\u0430\u044f \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u0447\u043b\u0435\u043d \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u0438\u0437 <code>Ts<\/code> \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443\u0434\u0430\u043b\u0438\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u0447\u043b\u0435\u043d \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0451, \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0445\u043e\u0442\u044f \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438 \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e.<br \/>  \u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432 <strong>C++<\/strong> \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0440\u0430\u0441\u0441\u043b\u0430\u0431\u043b\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 \u0431\u044b <abbr title=\"raw\">\u0433\u043e\u043b\u043e\u0435<\/abbr> \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u043e\u0435 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 \u0432 <code>Ts<\/code>\u00a0\u2014 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0441\u043f\u043e\u0439\u043b\u0435\u0440: \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043e\u043d\u0438 \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u0434\u0430\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 <abbr title=\"trait\">\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e<\/abbr> \u0434\u043b\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b:  <\/p>\n<blockquote><p> <strong>20.10.7.6 [meta.trans.other]<\/strong>  <\/p>\n<pre><code class=\"cpp\">template &lt;std::size_t Len, class... Types&gt;   struct aligned_union; <\/code><\/pre>\n<p>   <\/p>\n<ul>\n<li>\u0423\u0441\u043b\u043e\u0432\u0438\u0435: \u0414\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043e\u0434\u0438\u043d \u0442\u0438\u043f.<\/li>\n<li>\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438: typedef \u043d\u0430 \u0442\u0438\u043f \u0447\u043b\u0435\u043d\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c <abbr title=\"Plain Old Data\u00a0\u2014 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445\">POD<\/abbr>-\u0442\u0438\u043f\u043e\u043c, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b\u043c \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0447\u0435\u0439 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 <code>Types<\/code>; \u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 <code>Len<\/code>. \u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0447\u043b\u0435\u043d <code>alignment_value<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043e\u0439 \u0442\u0438\u043f\u0430 <code>std::size_t<\/code>, \u0447\u044c\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u043e\u0436\u0430\u0439\u0449\u0435\u0435 \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u0438\u043f\u043e\u0432, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 <code>Types<\/code>.<\/li>\n<\/ul>\n<p>  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>20.10.7.6 [meta.trans.other]<\/strong>  <\/p>\n<pre><code class=\"cpp\">template &lt;std::size_t Len, class... Types&gt;   struct aligned_union; <\/code><\/pre>\n<p>   <\/p>\n<ul>\n<li>Condition: At least one type is provided.<\/li>\n<li>Comments: The member typedef type shall be a POD type suitable for use as uninitialized storage for any object whose type is listed in <code>Types<\/code>; its size shall be at least <code>Len<\/code>. The static member <code>alignment_value<\/code> shall be an integral constant of type <code>std::size_t<\/code> whose value is the strictest alignment of all types listed in <code>Types<\/code>.<\/li>\n<\/ul>\n<p>   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0443\u0436\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u043e \u0438\u0437 <abbr title=\"working draft\">\u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a\u0430<\/abbr>\u00a0\u2014 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0440\u0438\u0445\u043e\u0434\u043e\u043c \u0440\u0430\u0441\u0441\u043b\u0430\u0431\u043b\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439\u00a0\u2014 \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u043c \u043d\u0430 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0430\u043d\u0438\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u0432 <strong>C++14<\/strong> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c:  <\/p>\n<pre><code class=\"cpp\">template &lt;std::size_t Len, typename ...Types&gt; struct aligned_union {   static constexpr std::size_t alignment_value = std::max({alignof(Types)...});   struct type {     alignas(alignment_value) unsigned char _[std::max({Len, sizeof(Types)...})];   }; }; <\/code><\/pre>\n<p>  \u0421 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>aligned_union<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f <code>variant&lt;Ts&gt;<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"cpp\">template &lt;typename ...Ts&gt; class variant {   template &lt;typename T&gt; struct _index_of { \/*...*\/ }; \/\/ \u0438\u043d\u0434\u0435\u043a\u0441 T \u0432 Ts..., \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u0441 0  public:   static constexpr std::size_t npos = std::size_t(-1);    variant() noexcept     : _which{npos}   {}    template &lt;typename T&gt;   variant(T const&amp; v)     : _which{_index_of&lt;T&gt;::value}   {     new (target&lt;T&gt;()) T(v); \/\/ \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u0442 \u0442\u0438\u043f T \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438                             \/\/ \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e\u0449\u0435\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new   }    \/*...*\/    std::size_t which() const noexcept {     return _which;   }    template &lt;typename T&gt;   T* target() noexcept {     return _which == _index_of&lt;T&gt;::value ?       static_cast&lt;T*&gt;(static_cast&lt;void*&gt;(&amp;_storage)) : nullptr;   }    template &lt;typename T&gt;   T const* target() const noexcept {     return _which == _index_of&lt;T&gt;::value ?       static_cast&lt;T const*&gt;(static_cast&lt;void const*&gt;(&amp;_storage)) : nullptr;   }  private:   std::size_t _which;   typename std::aligned_union&lt;0, Ts...&gt;::type _storage; }; <\/code><\/pre>\n<p>  \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0447\u043b\u0435\u043d (\u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0432\u043e\u0439 \u0438\u043c\u0435\u0435\u0442\u0441\u044f). \u0418 \u0441\u043d\u043e\u0432\u0430, \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>switch<\/code> \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438\u00a0\u2014 \u0445\u043e\u0442\u044f, \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0432\u0440\u044f\u0434 \u043b\u0438 \u0432\u0441\u0451 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u043e\u0441\u044c \u0431\u044b\u00a0\u2014 \u0438 \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u043b\u043e \u0431\u044b \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:  <\/p>\n<pre><code class=\"cpp\">struct _destructor {   template &lt;typename T&gt;   static void call(void* ptr) {     static_cast&lt;T*&gt;(ptr)-&gt;~T();   } };  variant&lt;Ts...&gt;::~variant() {   apply&lt;_destructor, Ts...&gt;(_which, &_storage); }  template &lt;typename F&gt; void apply(std::size_t \/*which*\/, void* \/*storage*\/) {}  template &lt;typename F, typename T, typename ...Ts&gt; void apply(std::size_t which, void* storage) {   if (which == 0) { F::template call&lt;T&gt;(storage); }   else { apply&lt;F, Ts...&gt;(which - 1, storage); } } <\/code><\/pre>\n<p>  \u041d\u0435\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>apply<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432, \u043f\u043e\u0434\u043e\u0431\u043d\u043e \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <code>switch<\/code>, \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c \u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c:  <\/p>\n<pre><code class=\"cpp\">template &lt;typename F, typename ...Ts&gt; void apply(std::size_t which, void* storage) {   using fun_ptr = void(*)(void*);   static constexpr fun_ptr table[] = {&amp;F::template call&lt;Ts&gt;...};    if (which &lt; sizeof...(Ts)) { table[which](storage); } } <\/code><\/pre>\n<p>  \u041d\u0435\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u0451\u0442 \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e \u0441 \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0442\u0438\u043f\u043e\u0432 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 <code>Ts<\/code>\u00a0\u2014 \u0432 \u0432\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0446\u0435\u043d\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f.<\/p>\n<h2><a name=\"trivially-copyable\"><\/a>\u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b<\/h2>\n<p>  <abbr title=\"trivially copyable\">\u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u0439<\/abbr> \u0442\u0438\u043f\u00a0\u2014 \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d \u043f\u0443\u0442\u0451\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0435\u0433\u043e \u0431\u0438\u0442\u043e\u0432\u00a0\u2014 \u0442\u043e \u0435\u0441\u0442\u044c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/string\/byte\/memcpy\"><code>std::memcpy<\/code><\/a>.  <\/p>\n<blockquote><p> <strong>3.9 [basic.types]\/2<\/strong> \u0414\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (\u043a\u0440\u043e\u043c\u0435 \u043f\u043e\u0434\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430) \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430 <code>T<\/code>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043b\u0438 \u043e\u043d\u0438 \u0438\u043b\u0438 \u043d\u0435\u0442 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>T<\/code>, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0435\u0433\u043e \u0431\u0430\u0439\u0442\u044b (1.7) \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 <code>char<\/code> \u0438\u043b\u0438 <code>unsigned char<\/code>. \u0415\u0441\u043b\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <code>char<\/code> \u0438\u043b\u0438 <code>unsigned char<\/code> \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0432\u043e\u0451 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. [&#8230;]<br \/>   <strong>3.9 [basic.types]\/3<\/strong> \u0414\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430 <code>T<\/code>, \u0435\u0441\u043b\u0438 \u0434\u0432\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 <code>T<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b <code>obj1<\/code> \u0438 <code>obj2<\/code> \u0442\u0438\u043f\u0430 <code>T<\/code>, \u0433\u0434\u0435 \u043b\u0438\u0431\u043e <code>obj1<\/code>, \u043b\u0438\u0431\u043e <code>obj2<\/code> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 <code>obj1<\/code> \u0431\u0430\u0439\u0442\u044b (1.7) \u043a\u043e\u043f\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 <code>obj2<\/code>, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 <code>obj2<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0438 <code>obj1<\/code>. [&#8230;]  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>3.9 [basic.types]\/2<\/strong> For any object (other than a base-class subobject) of trivially copyable type <code>T<\/code>, whether or not the object holds a valid value of type <code>T<\/code>, the underlying bytes (1.7) making up the object can be copied into an array of <code>char<\/code> or <code>unsigned char<\/code>. If the content of the array of <code>char<\/code> or <code>unsigned char<\/code> is copied back into the object, the object shall subsequently hold its original value. [&#8230;]<br \/>   <strong>3.9 [basic.types]\/3<\/strong> For any trivially copyable type <code>T<\/code>, if two pointers to <code>T<\/code> point to distinct <code>T<\/code> objects <code>obj1<\/code> and <code>obj2<\/code>, where neither <code>obj1<\/code> nor <code>obj2<\/code> is a base-class subobject, if the underlying bytes (1.7) making up <code>obj1<\/code> are copied into <code>obj2<\/code>, <code>obj2<\/code> shall subsequently hold the same value as <code>obj1<\/code>. [&#8230;]   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0447\u043b\u0435\u043d\u043e\u0432 \u0441\u0430\u043c\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u043c, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u043c \u0434\u043b\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0434\u043b\u044f \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u041e\u0442\u0441\u044e\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e <code>variant<\/code> \u0441 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c\u0441\u044f \u0431\u044b\u0442\u044c \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u043c.  <\/p>\n<blockquote><p> <strong>9 [class]\/6<\/strong> \u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u00a0\u2014 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:   <\/p>\n<ul>\n<li>\u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (12.8),<\/li>\n<li>\u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f (12.8),<\/li>\n<li>\u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043f\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f (13.5.3, 12.8),<\/li>\n<li>\u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f (13.5.3, 12.8) \u0438<\/li>\n<li>\u0438\u043c\u0435\u0435\u0442 \u0442\u0440\u0438\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 (12.4).<\/li>\n<\/ul>\n<p>   [&#8230;]  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>9 [class]\/6<\/strong> A trivially copyable class is a class that:   <\/p>\n<ul>\n<li>has no non-trivial copy constructors (12.8),<\/li>\n<li>has no non-trivial move constructors (12.8),<\/li>\n<li>has no non-trivial copy assignment operators (13.5.3, 12.8),<\/li>\n<li>has no non-trivial move assignment operators (13.5.3, 12.8), and<\/li>\n<li>has a trivial destructor (12.4).<\/li>\n<\/ul>\n<p>   [&#8230;]   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u044b\u0431\u0440\u0430\u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>variant<\/code>, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0442\u0438\u043f\u044b \u0432 <code>Ts<\/code> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438. \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u044b, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438\u00a0\u2014 \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043b\u0438\u0431\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e, \u043b\u0438\u0431\u043e \u044f\u0432\u043d\u043e \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u0430\u043a \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043f\u0440\u0438 \u0438\u0445 \u043f\u0435\u0440\u0432\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0434\u043b\u044f \u043d\u0438\u0445 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438; \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0438\u0445 \u0431\u0438\u0442\u044b \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0434\u0438\u0441\u043a\u0440\u0438\u043c\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u043c, \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0436\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c.<br \/>  \u041d\u043e \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u0437\u0430\u0433\u0432\u043e\u0437\u0434\u043a\u0430: \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u043c, \u0445\u043e\u0442\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u0447\u043b\u0435\u043d, \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u0430\u044f \u043f\u0440\u0438 \u0435\u0433\u043e \u043f\u0435\u0440\u0432\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0439. \u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043a\u043b\u0430\u0441\u0441 <a href=\"http:\/\/www.boost.org\/libs\/core\/doc\/html\/core\/noncopyable.html\"><code>boost::noncopyable<\/code><\/a>:  <\/p>\n<pre><code class=\"cpp\">class noncopyable { protected:   constexpr noncopyable() = default;   noncopyable(noncopyable const&amp;) = delete;   noncopyable&amp; operator=(noncopyable const&amp;) = delete;   ~noncopyable() = default; }; <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0441\u044e\u0440\u043f\u0440\u0438\u0437\u043e\u043c \u0442\u043e, \u0447\u0442\u043e <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/types\/is_trivially_copyable\"><code>std::is_trivially_copyable<\/code><\/a> \u0432\u044b\u0432\u043e\u0434\u0438\u0442 <code>true<\/code> \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 <code>noncopyable<\/code>. \u0415\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0441\u044e\u0440\u043f\u0440\u0438\u0437\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>variant&lt;noncopyable&gt;<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u044b <code>noncopyable<\/code> \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f. \u042d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438, \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u0438\u0437 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0433\u043e\u043b\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430.<\/p>\n<h2><a name=\"trivially-destructible\"><\/a>\u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0443\u0448\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b<\/h2>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0436\u043d\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0435\u0439 \u0442\u0438\u043f\u043e\u0432 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f <abbr title=\"trivially destructible\">\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0443\u0448\u0430\u0435\u043c\u044b\u043c\u0438<\/abbr>.  <\/p>\n<blockquote><p> <strong>12.4 [class.dtor]\/5<\/strong> [&#8230;] \u0414\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c, \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438 \u0435\u0441\u043b\u0438:   <\/p>\n<ul>\n<li>\u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c,<\/li>\n<li>\u0432\u0441\u0435 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u043c\u0435\u044e\u0442 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u0438<\/li>\n<li>\u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0442\u0438\u043f \u043a\u043b\u0430\u0441\u0441\u0430 (\u0438\u043b\u0438 \u0442\u0438\u043f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432), \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u043c\u0435\u0435\u0442 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440.<\/li>\n<\/ul>\n<p>   \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c.  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>12.4 [class.dtor]\/5<\/strong> [&#8230;] A destructor is trivial if it is not user-provided and if:   <\/p>\n<ul>\n<li>the destructor is not virtual,<\/li>\n<li>all of the direct base classes of its class have trivial destructors, and<\/li>\n<li>for all of the non-static data members of its class that are of class type (or array thereof), each such class has a trivial destructor.<\/li>\n<\/ul>\n<p>   Otherwise, the destructor is non-trivial.   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u042d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u0430\u0436\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u043a <abbr title=\"literal type\">\u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0442\u0438\u043f\u0443<\/abbr>\u00a0\u2014 \u0447\u044c\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 <code>constexpr<\/code>-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u00a0\u2014 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0445 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0437\u0440\u0443\u0448\u0430\u0435\u043c\u043e\u0441\u0442\u044c.  <\/p>\n<blockquote><p> <strong>3.9 [basic.types]\/10<\/strong> \u0422\u0438\u043f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c, \u0435\u0441\u043b\u0438 \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f:   <\/p>\n<ul>\n<li>[&#8230;]<\/li>\n<li> \u0442\u0438\u043f\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 (\u043f\u0443\u043d\u043a\u0442 9), \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0449\u0438\u043c \u0432\u0441\u0435\u043c\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438:<br \/> \n<ul>\n<li>\u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440,<\/li>\n<li>\u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <abbr title=\"aggregate type\">\u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c<\/abbr> (8.5.1) \u0438\u043b\u0438 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043e\u0434\u0438\u043d <code>constexpr<\/code>-\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438\u043b\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0438<\/li>\n<li>\u0432\u0441\u0435 \u0435\u0433\u043e \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0447\u043b\u0435\u043d\u044b \u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f <abbr title=\"non-volatile\">\u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u044b\u043c\u0438<\/abbr> \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438.<\/li>\n<\/ul>\n<p>   <\/li>\n<\/ul>\n<p>  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>3.9 [basic.types]\/10<\/strong> A type is a literal type if it is:   <\/p>\n<ul>\n<li>[&#8230;]<\/li>\n<li>a class type (Clause 9) that has all of the following properties:<br \/> \n<ul>\n<li>it has a trivial destructor,<\/li>\n<li>it is an aggregate type (8.5.1) or has at least one constexpr constructor or constructor template that is not a copy or move constructor, and<\/li>\n<li>all of its non-static data members and base classes are of non-volatile literal types.<\/li>\n<\/ul>\n<p>   <\/li>\n<\/ul>\n<p>   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c, \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043e\u0434\u0438\u043d \u0438\u0437 \u0435\u0433\u043e \u0447\u043b\u0435\u043d\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u043b\u0435\u043d\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0443\u0448\u0430\u0435\u043c\u044b\u043c\u0438. \u041e\u0442\u0441\u044e\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e <code>variant<\/code> \u043f\u0440\u0438 \u044d\u0442\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c\u0441\u044f \u0431\u044b\u0442\u044c \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c. \u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>variant<\/code> \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0442\u0438\u043f\u044b \u0432 <code>Ts<\/code> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0443\u0448\u0430\u0435\u043c\u044b\u043c\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u043e\u043d\u0430 \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0440\u0435\u0434\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 <code>void<\/code> \u043a \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442:  <\/p>\n<blockquote><p> <strong>5.19 [expr.const]\/2<\/strong> \u0423\u0441\u043b\u043e\u0432\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>e<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044f\u0434\u0440\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <code>e<\/code>, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b (1.9), \u043d\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439:   <\/p>\n<ul>\n<li>[&#8230;]<\/li>\n<li>\u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0437 \u0442\u0438\u043f\u0430 <code>cv void*<\/code> \u043a \u0442\u0438\u043f\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442;<\/li>\n<li>[&#8230;]<\/li>\n<\/ul>\n<p>  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>5.19 [expr.const]\/2<\/strong> A conditional-expression <code>e<\/code> is a core constant expression unless the evaluation of <code>e<\/code>, following the rules of the abstract machine (1.9), would evaluate one of the following expressions:   <\/p>\n<ul>\n<li>[&#8230;]<\/li>\n<li>a conversion from type <code>cv void*<\/code> to a pointer-to-object type;<\/li>\n<li>[&#8230;]<\/li>\n<\/ul>\n<p>   <\/p><\/blockquote>\n<p>  <\/div>\n<\/div>\n<p>  \u0418 \u0441\u043d\u043e\u0432\u0430, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u044b\u0440\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0442\u043e\u043c \u0436\u0435 \u0443\u0440\u043e\u0432\u043d\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0438\u0447\u044c, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u0435\u0433\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<h1><a name=\"what-lies-ahead\"><\/a>\u041e \u0447\u0451\u043c \u0435\u0449\u0451 \u043d\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043e<\/h1>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043d\u0430 \u0441\u044b\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u00a0\u2014 \u0445\u043e\u0442\u044f \u0438 \u043e\u043f\u0440\u0430\u0432\u0434\u044b\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0446\u0435\u043d\u0443\u00a0\u2014 \u043d\u0435 \u0432\u044b\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u0440\u0438\u0442\u0438\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u0435\u0451 \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442 \u0434\u043e \u043f\u0440\u0435\u0434\u0435\u043b\u0430. \u041e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u0435 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0435 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043b\u0435\u0436\u0430\u0449\u0435\u0433\u043e \u0432 \u0441\u0432\u043e\u0435\u0439 \u043e\u0441\u043d\u043e\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u043e \u043c\u043e\u0433\u043b\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c.   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/244573\/\"> http:\/\/habrahabr.ru\/post\/244573\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       \u041d\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u043c\u0435\u043d\u044f \u0441\u043f\u043e\u0434\u0432\u0438\u0433 <a href=\"\/post\/244497\/#comment_8153531\">\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/a> \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <b><a href=\"http:\/\/habrahabr.ru\/users\/encyclopedist\/\" class=\"user_link\">encyclopedist<\/a><\/b> \u043a \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"\/post\/244497\/\">\u00ab\u0424\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0431\u0435\u0437 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0432 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438\u00bb<\/a>. \u0421\u0442\u0430\u0442\u044c\u044f \u043c\u0435\u043d\u044f \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0430, \u043d\u043e \u0431\u0435\u0433\u043b\u043e\u0435 <i>\u0433\u0443\u0433\u043b\u0435\u043d\u0438\u0435<\/i> \u043d\u0435 \u0432\u044b\u044f\u0432\u0438\u043b\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430. \u00ab\u041d\u0435\u043f\u043e\u0440\u044f\u0434\u043e\u043a.\u00bb\u00a0\u2014 \u043f\u043e\u0434\u0443\u043c\u0430\u043b \u044f\u00a0\u2014 \u00ab\u0422\u0430\u043a\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e \u0421++ \u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u0430 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a. \u041d\u0430\u0434\u043e \u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c.\u00bb<\/p>\n<p>  <b>\u041e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/b>  <\/p>\n<ol>\n<li><a href=\"#introduction\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/a><\/li>\n<li><a href=\"#design\">\u041f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><\/li>\n<li> <a href=\"#implementation\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/a><br \/> \n<ul>\n<li><a href=\"#trivially-copyable\">\u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b<\/a><\/li>\n<li><a href=\"#trivially-destructible\">\u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0443\u0448\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b<\/a><\/li>\n<\/ul>\n<p>   <\/li>\n<li><a href=\"#what-lies-ahead\">\u041e \u0447\u0451\u043c \u0435\u0449\u0451 \u043d\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043e<\/a><\/li>\n<\/ol>\n<p>  \u0420\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u044f \u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 <a href=\"https:\/\/github.com\/eggs-cpp\/variant\">Eggs.Variant<\/a>\u00a0\u2014 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u043c \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c <abbr title=\"discriminated union\">\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438<\/abbr> \u043d\u0430 <strong>C++11\/14<\/strong>.<\/p>\n<h1><a name=\"introduction\"><\/a>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h1>\n<p>  <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/union\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/a>\u00a0\u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0432\u043e\u0438\u0445 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432. \u041e\u043d \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u0442\u0430, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0434\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0438\u0437 \u0435\u0433\u043e \u0447\u043b\u0435\u043d\u043e\u0432.  <\/p>\n<blockquote><p> <strong>9 [class]\/5<\/strong> \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u00a0\u2014 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0439 \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <code>union<\/code>; \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0432\u043e\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432 (9.5). [&#8230;]<br \/>   <strong>9.5 [class.union]\/1<\/strong> \u0412 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c, \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0435\u0433\u043e \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432. [&#8230;] \u0420\u0430\u0437\u043c\u0435\u0440 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u0435\u043d \u0434\u043b\u044f \u0432\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0438\u0437 \u0435\u0433\u043e \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0447\u043b\u0435\u043d\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0447\u043b\u0435\u043d \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a, \u0441\u043b\u043e\u0432\u043d\u043e \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0447\u043b\u0435\u043d\u043e\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0412\u0441\u0435 \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0447\u043b\u0435\u043d\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0430\u0434\u0440\u0435\u0441.  <\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/b><\/p>\n<div class=\"spoiler_text\">\n<blockquote><p> <strong>9 [class]\/5<\/strong> A union is a class defined with the class-key union; it holds at most one data member at a time (9.5). [&#8230;]<br \/>   <strong>9.5 [class.union]\/1<\/strong> In a union, at most one of the non-static data members can be active at any time, that is, the value of at most one of the non-static data members can be stored in a union at any time. [&#8230;] The size of a union is sufficient to contain the largest of its non-static data members. Each non-static data member is allocated as if it were the sole member of a struct. All non-static data members of a union object have the same address.   <\/p><\/blockquote>\n<p>  <\/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-244573","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/244573","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=244573"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/244573\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=244573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=244573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=244573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}