{"id":363405,"date":"2024-05-21T01:55:11","date_gmt":"2024-05-21T01:55:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=363405"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T01:55:11","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=363405","title":{"rendered":"<span>\u042d\u0432\u043e\u043b\u044e\u0446\u0438\u044f enum<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u2014 \u044d\u0442\u043e \u0437\u0434\u043e\u0440\u043e\u0432\u043e. \u0422\u0438\u043f\u044b \u2014 \u044d\u0442\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u2014 \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435. \u0410 <code>enum<\/code> \u043a\u043b\u0430\u0441\u0441\u044b \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0430\u043d\u0442\u0430\u0441\u0442\u0438\u043a\u0430.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0433\u043e\u0434\u0443 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u0442\u043e\u043c, <a href=\"https:\/\/www.sandordargo.com\/blog\/2022\/04\/06\/use-strong-types-instead-booleans\">\u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u043b\u0435\u0432\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/a>. \u041e\u0434\u043d\u043e \u0438\u0437 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0438\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0432\u043c\u0435\u0441\u0442\u043e \u0433\u043e\u043b\u044b\u0445 \u0431\u0443\u043b\u0435\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043d\u0438\u043c\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043b\u044e\u0431\u0438\u043c\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430.<\/p>\n<h3>Unscoped \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 C++, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b \u0438\u0437 C. \u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0414\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044f\u0432\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">enum Color { red, green, blue };<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u0432\u0435 \u0432\u0435\u0449\u0438:<\/p>\n<ul>\n<li>\n<p>\u0421\u0430\u043c\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 (<code>enum<\/code>) \u2014 \u044d\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0447\u0438\u0441\u043b\u0435, \u0434\u0430\u0436\u0435 \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u043d\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u043e\u0434\u043d\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u0415\u0441\u043b\u0438 \u0432\u044b \u0431\u0435\u0440\u0435\u0442\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Color<\/code>, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u0437\u044f\u0442 \u043e\u0434\u0438\u043d \u0446\u0432\u0435\u0442. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442\u0435 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 \u043e\u0434\u043d\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 <code>Color::red<\/code>, \u0447\u0435\u043c \u0441 <code>Colors::red<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435, \u0430 \u043d\u0435 \u043a\u0430\u043f\u0441\u043e\u043c (<em>ALL_CAPS<\/em>)! \u0425\u043e\u0442\u044f \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u0447\u0442\u043e \u0432\u044b \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0438\u0445 \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0430\u043f\u0441\u043e\u043c. \u042f \u0442\u043e\u0436\u0435 \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u043b. \u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u044f \u0432 \u0438\u0442\u043e\u0433\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0441\u0432\u043e\u0435\u0439 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0438? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b core guidelines, \u0438 \u0432 <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum5-dont-use-all_caps-for-enumerators\">Enum.5<\/a> \u0447\u0435\u0442\u043a\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043f\u0441<em>, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432 \u0441 \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u043c\u0438<\/em>. \u041a\u0441\u0442\u0430\u0442\u0438, \u0432 <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum5-dont-use-all_caps-for-enumerators\">Enum.1<\/a> \u0442\u0430\u043a\u0436\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u0430 \u043d\u0435 \u043c\u0430\u043a\u0440\u043e\u0441\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++11, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f enum \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u043e\u0441\u044c. \u0412 C++11 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f (underlying type) \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d, \u0442\u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u043d\u043e \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f.<\/p>\n<p>\u041a\u0430\u043a \u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c? \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435! \u0425\u043e\u0442\u044f \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0443\u0440\u043e\u0432\u043d\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430:<\/p>\n<pre><code class=\"cpp\">enum Color : int { red, green, blue };<\/code><\/pre>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u044b \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u0431\u0443\u0434\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u044b\u043c. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f! \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0430. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u044f\u0432\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435:<\/p>\n<pre><code class=\"cpp\">main.cpp:4:19: error: underlying type 'std::string' {aka 'std::__cxx11::basic_string&lt;char>'} of 'Color' must be an integral type     4 | enum Color : std::string { red, green, blue };       |                   ^~~~~~<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum7-specify-the-underlying-type-of-an-enumeration-only-when-necessary\">core guidelines \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443<\/a>! \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e.<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e? \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0432\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e, \u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">enum Direction : char { north, south, east, west,    northeast, northwest, southeast, southwest }; <\/code><\/pre>\n<ul>\n<li>\n<p>\u0418\u043b\u0438, \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 (forward declare) <code>enum<\/code>, \u0432\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0438 \u0442\u0438\u043f:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">enum Direction : char; void navigate(Direction d);  enum Direction : char { north, south, east, west,      northeast, northwest, southeast, southwest };<\/code><\/pre>\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u0432\u0441\u0435\u0445 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f <code>constexpr<\/code>.<\/p>\n<pre><code class=\"cpp\">enum Color : int { red = 0, green = 1, blue = 2 };<\/code><\/pre>\n<p>\u0418 \u0441\u043d\u043e\u0432\u0430 <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum8-specify-enumerator-values-only-when-necessary\">core guidelines \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e<\/a>, \u0435\u0441\u043b\u0438 \u043d\u0430 \u044d\u0442\u043e \u043d\u0435\u0442 \u043e\u0441\u043e\u0431\u043e\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438! \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u043d\u0430\u0447\u043d\u0435\u0442\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u0440\u0442\u0438\u0442\u044c. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044f.<\/p>\n<ul>\n<li>\n<p>\u0425\u043e\u0440\u043e\u0448\u0438\u043c \u044e\u0437\u043a\u0435\u0439\u0441\u043e\u043c \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0435 \u043c\u0435\u0441\u044f\u0446\u044b \u0438 \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0441 \u043d\u0443\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">enum Month { jan = 1, feb, mar, apr, may, jun,                  jul, august, sep, oct, nov, dec };<\/code><\/pre>\n<ul>\n<li>\n<p>\u0414\u0440\u0443\u0433\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">enum altitude: char {   high = 'h',   low = 'l' }; <\/code><\/pre>\n<ul>\n<li>\n<p>\u0415\u0449\u0435 \u043e\u0434\u043d\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u044d\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439. \u0422\u043e \u0435\u0441\u0442\u044c \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0434\u0432\u043e\u0439\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">enum access_type { read = 1, write = 2, exec = 4 };<\/code><\/pre>\n<h3>Scoped \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>enum<\/code> <code>EnumName{};<\/code>. \u0412 C++11 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 <code>scoped<\/code> (\u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438) <code>enum<\/code>. \u041e\u043d\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 <code>class<\/code>, \u043b\u0438\u0431\u043e <code>struct<\/code> (\u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b).<\/p>\n<p>\u0418\u0445 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">enum class Color { red, green, blue };<\/code><\/pre>\n<p>\u0414\u043b\u044f <code>scoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435, \u0438 \u044d\u0442\u043e <code>int<\/code>. \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f. \u0415\u0441\u043b\u0438 \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c <code>int<\/code>, \u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e:<\/p>\n<pre><code class=\"cpp\">enum class Color;<\/code><\/pre>\n<p>\u041d\u043e \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f, \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u0438\u0445 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f?<\/p>\n<p>Unscoped \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u044f\u0432\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u044b \u043a \u0441\u0432\u043e\u0435\u043c\u0443 \u0431\u0430\u0437\u043e\u0432\u043e\u043c\u0443 \u0442\u0438\u043f\u0443. \u041d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0438 \u0443 <code>scoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 <em>&#171;\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438&#187;<\/em>. \u0418\u043c\u0435\u043d\u043d\u043e \u0438\u0437-\u0437\u0430 \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum3-prefer-class-enums-over-plain-enums\">core guidelines \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c scoped, \u0430 \u043d\u0435 unscoped \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/a>.<\/p>\n<pre><code class=\"cpp\">void Print_color(int color);  enum Web_color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF }; enum Product_info { red = 0, purple = 1, blue = 2 };  Web_color webby = Web_color::blue;  \/\/ Clearly at least one of these calls is buggy. Print_color(webby); Print_color(Product_info::blue);<\/code><\/pre>\n<p><code>Unscoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442 \u0441\u0432\u043e\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u0438 \u0432 \u043e\u0431\u044a\u0435\u043c\u043b\u044e\u0449\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0443 \u0438\u043c\u0435\u043d. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>scoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<pre><code class=\"cpp\">enum UnscopedColor { red, green, blue }; enum class ScopedColor { red, green, blue };  int main() {     [[maybe_unused]] UnscopedColor uc = red;     \/\/ [[maybe_unused]] ScopedColor sc = red; \/\/ Doesn't compile     [[maybe_unused]] ScopedColor sc = ScopedColor::red; }<\/code><\/pre>\n<h3>\u0427\u0442\u043e \u0435\u0449\u0435?<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 <code>scoped\/unscoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0447\u0435\u043c \u043e\u043d\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u044f\u0437\u044b\u043a \u0438\u043b\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430.<\/p>\n<h4>std::is_enum<\/h4>\n<p>\u0412 C++11 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>&lt;type_traits><\/code>. \u041e\u043d \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0442\u0438\u043f\u043e\u0432. \u041d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e <code>is_enum<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0438\u043b\u0438 \u043d\u0435\u0442. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>true<\/code> \u043a\u0430\u043a \u0434\u043b\u044f <code>scoped<\/code>, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f <code>unscoped<\/code> \u0432\u0435\u0440\u0441\u0438\u0439.<\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++17, \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 <code>is_enum_v<\/code>.<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;type_traits>  enum UnscopedColor { red, green, blue }; enum class ScopedColor { red, green, blue }; struct S{};  int main() {     std::cout &lt;&lt; std::boolalpha               &lt;&lt; std::is_enum&lt;UnscopedColor>::value &lt;&lt; '\\n'               &lt;&lt; std::is_enum&lt;ScopedColor>::value &lt;&lt; '\\n'               &lt;&lt; std::is_enum_v&lt;S> &lt;&lt; '\\n'; }<\/code><\/pre>\n<h4>std::underlying_type<\/h4>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432 C++11 \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d <code>std::underlying_type<\/code>. \u041e\u043d \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0414\u043e C++20, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u043e\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u0438\u043b\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c, \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0434\u043b\u044f \u043d\u0435\u043f\u043e\u043b\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0412 C++14 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0445\u0435\u043b\u043f\u0435\u0440 <code>std::underlying_type_t<\/code>.<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;type_traits>  enum UnscopedColor { red, green, blue }; enum class ScopedColor { red, green, blue }; enum class CharBasedColor : char { red = 'r', green = 'g', blue = 'b' };  int main() {     constexpr bool isUnscopedColorInt = std::is_same_v&lt; std::underlying_type&lt;UnscopedColor>::type, int >;   constexpr bool isScopedColorInt = std::is_same_v&lt; std::underlying_type_t&lt;ScopedColor>, int >;   constexpr bool isCharBasedColorInt = std::is_same_v&lt; std::underlying_type_t&lt;CharBasedColor>, int >;   constexpr bool isCharBasedColorChar = std::is_same_v&lt; std::underlying_type_t&lt;CharBasedColor>, char >;    std::cout     &lt;&lt; \"underlying type for 'UnscopedColor' is \" &lt;&lt; (isUnscopedColorInt ? \"int\" : \"non-int\") &lt;&lt; '\\n'     &lt;&lt; \"underlying type for 'ScopedColor' is \" &lt;&lt; (isScopedColorInt ? \"int\" : \"non-int\") &lt;&lt; '\\n'     &lt;&lt; \"underlying type for 'CharBasedColor' is \" &lt;&lt; (isCharBasedColorInt ? \"int\" : \"non-int\") &lt;&lt; '\\n'     &lt;&lt; \"underlying type for 'CharBasedColor' is \" &lt;&lt; (isCharBasedColorChar ? \"char\" : \"non-char\") &lt;&lt; '\\n'     ; }<\/code><\/pre>\n<h4>\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c using \u0432 C++20<\/h4>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++20, \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>using<\/code>. \u041e\u043d \u0432\u0432\u043e\u0434\u0438\u0442 \u0438\u043c\u0435\u043d\u0430 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u0432 \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u042d\u0442\u0430 \u0444\u0438\u0447\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u043c\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c <code>using<\/code> \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438.<\/p>\n<pre><code class=\"cpp\">#include &lt;type_traits>  enum class ScopedColor { red, green, blue }; enum class CharBasedColor : char { red = 'r', green = 'g', blue = 'b' };  int main() {   using enum ScopedColor; \/\/ OK!   using enum CharBasedColor; \/\/ error: 'CharBasedColor CharBasedColor::red' conflicts with a previous declaration }<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432 <code>unscoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0435\u043d. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0437 <code>UnscopedColor<\/code> \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b <code>red<\/code>, <code>green<\/code> \u0438 <code>blue<\/code>, \u043e\u0434\u043d\u0430\u043a\u043e <code>using<\/code> <code>ScopedColor<\/code> \u0441 \u0442\u0435\u043c\u0438 \u0436\u0435 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"cpp\">#include &lt;type_traits>  enum UnscopedColor { red, green, blue }; enum class ScopedColor { red, green, blue };  int main() {   using enum ScopedColor; }<\/code><\/pre>\n<h4>C++23 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 std::is_scoped_enum<\/h4>\n<p>\u0412 C++23 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 <code>&lt;type_traits><\/code> \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438, \u2014 <code>std::is_scoped_enum<\/code> \u0438 \u0435\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>std::is_scoped_enum_v<\/code>. \u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u043c \u043d\u0438\u0436\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u043c, \u043e\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0435\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>scoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;type_traits>   enum UnscopedColor { red, green, blue }; enum class ScopedColor { red, green, blue }; struct S{};  int main()  {     std::cout &lt;&lt; std::boolalpha;     std::cout &lt;&lt; std::is_scoped_enum&lt;UnscopedColor>::value &lt;&lt; '\\n';     std::cout &lt;&lt; std::is_scoped_enum_v&lt;ScopedColor> &lt;&lt; '\\n';     std::cout &lt;&lt; std::is_scoped_enum_v&lt;S> &lt;&lt; '\\n';     std::cout &lt;&lt; std::is_scoped_enum_v&lt;int> &lt;&lt; '\\n'; } \/* false true false false *\/<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0444\u0438\u0447\u0438 C++23, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0444\u043b\u0430\u0433 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 <code>-std=c++2b<\/code>.<\/p>\n<h4>\u0412 C++23 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f std::to_underlying<\/h4>\n<p>\u0412 C++23 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>&lt;utility><\/code> \u0440\u0430\u0437\u0436\u0438\u0432\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>std::to_underlying<\/code>. \u041e\u043d\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0432 \u0435\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f. \u041a\u0430\u043a \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c, \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u043d\u043d\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445.<\/p>\n<p>\u0415\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 <code>static_cast<\/code>, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u043d\u043d\u0438\u043c \u0432\u0435\u0440\u0441\u0438\u044f\u043c: <code>static_cast&lt;std::underlying_type_t&lt;MyEnum>>(e);<\/code>.<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;type_traits> #include &lt;utility>   enum class ScopedColor { red, green, blue };  int main()  {     ScopedColor sc = ScopedColor::red;     [[maybe_unused]] int underlying = std::to_underlying(sc);     [[maybe_unused]] int underlyingEmulated = static_cast&lt;std::underlying_type_t&lt;ScopedColor>>(sc);     [[maybe_unused]] std::underlying_type_t&lt;ScopedColor> underlyingDeduced = std::to_underlying(sc); }<\/code><\/pre>\n<p>\u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0444\u0438\u0447\u0438 C++23, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0444\u043b\u0430\u0433 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 &#8212;<code>std=c++2b<\/code>.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043b\u0438 \u0432\u0441\u0435 \u0444\u0438\u0447\u0438 \u044f\u0437\u044b\u043a\u0430 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438. \u041c\u044b \u0443\u0432\u0438\u0434\u0435\u043b\u0438, \u0447\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f <code>scoped<\/code> \u0438 <code>unscoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c scoped \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0418 \u044d\u0442\u043e \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f \u0438\u0437 <a href=\"https:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#S-enum\">Core Guidelines<\/a>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043b\u0438.<\/p>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u0437\u0430 \u044d\u0442\u0438 \u0433\u043e\u0434\u044b \u043e\u0431\u043e\u0433\u0430\u0442\u0438\u043b\u0430\u0441\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0432 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438. \u0410 \u0435\u0449\u0435 \u043c\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u043b\u0438 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u0435 \u0438 \u0443\u0437\u043d\u0430\u043b\u0438, \u0447\u0442\u043e \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 \u043d\u0430\u043c C++23.<\/p>\n<blockquote>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0432\u0441\u0435\u0445 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0430 C++ \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0443 \u0432 C++. \u0427\u0435\u043c\u0443 \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f:<\/p>\n<p>\u2014 \u0432 \u043a\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c;<br \/>\u2014 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0432 C++;<br \/>\u2014 \u043a\u0430\u043a\u0430\u044f \u0446\u0435\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<p>\u0423\u0440\u043e\u043a \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0432\u0435\u0447\u0435\u0440\u043e\u043c 19 \u0434\u0435\u043a\u0430\u0431\u0440\u044f, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0439\u0442\u0435\u0441\u044c <a href=\"https:\/\/otus.pw\/IhZz\/\">\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435.<\/a><\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/781712\/\"> https:\/\/habr.com\/ru\/articles\/781712\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u2014 \u044d\u0442\u043e \u0437\u0434\u043e\u0440\u043e\u0432\u043e. \u0422\u0438\u043f\u044b \u2014 \u044d\u0442\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u2014 \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435. \u0410 <code>enum<\/code> \u043a\u043b\u0430\u0441\u0441\u044b \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0430\u043d\u0442\u0430\u0441\u0442\u0438\u043a\u0430.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0433\u043e\u0434\u0443 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u0442\u043e\u043c, <a href=\"https:\/\/www.sandordargo.com\/blog\/2022\/04\/06\/use-strong-types-instead-booleans\">\u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u043b\u0435\u0432\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/a>. \u041e\u0434\u043d\u043e \u0438\u0437 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0438\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0432\u043c\u0435\u0441\u0442\u043e \u0433\u043e\u043b\u044b\u0445 \u0431\u0443\u043b\u0435\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043d\u0438\u043c\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043b\u044e\u0431\u0438\u043c\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430.<\/p>\n<h3>Unscoped \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 C++, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b \u0438\u0437 C. \u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0414\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044f\u0432\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">enum Color { red, green, blue };<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u0432\u0435 \u0432\u0435\u0449\u0438:<\/p>\n<ul>\n<li>\n<p>\u0421\u0430\u043c\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 (<code>enum<\/code>) \u2014 \u044d\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0447\u0438\u0441\u043b\u0435, \u0434\u0430\u0436\u0435 \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u043d\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u043e\u0434\u043d\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u0415\u0441\u043b\u0438 \u0432\u044b \u0431\u0435\u0440\u0435\u0442\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Color<\/code>, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u0437\u044f\u0442 \u043e\u0434\u0438\u043d \u0446\u0432\u0435\u0442. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442\u0435 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 \u043e\u0434\u043d\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 <code>Color::red<\/code>, \u0447\u0435\u043c \u0441 <code>Colors::red<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435, \u0430 \u043d\u0435 \u043a\u0430\u043f\u0441\u043e\u043c (<em>ALL_CAPS<\/em>)! \u0425\u043e\u0442\u044f \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u0447\u0442\u043e \u0432\u044b \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0438\u0445 \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0430\u043f\u0441\u043e\u043c. \u042f \u0442\u043e\u0436\u0435 \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u043b. \u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u044f \u0432 \u0438\u0442\u043e\u0433\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0441\u0432\u043e\u0435\u0439 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0438? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b core guidelines, \u0438 \u0432 <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum5-dont-use-all_caps-for-enumerators\">Enum.5<\/a> \u0447\u0435\u0442\u043a\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043f\u0441<em>, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432 \u0441 \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u043c\u0438<\/em>. \u041a\u0441\u0442\u0430\u0442\u0438, \u0432 <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum5-dont-use-all_caps-for-enumerators\">Enum.1<\/a> \u0442\u0430\u043a\u0436\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u0430 \u043d\u0435 \u043c\u0430\u043a\u0440\u043e\u0441\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++11, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f enum \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u043e\u0441\u044c. \u0412 C++11 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f (underlying type) \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d, \u0442\u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u043d\u043e \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f.<\/p>\n<p>\u041a\u0430\u043a \u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c? \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435! \u0425\u043e\u0442\u044f \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0443\u0440\u043e\u0432\u043d\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430:<\/p>\n<pre><code class=\"cpp\">enum Color : int { red, green, blue };<\/code><\/pre>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u044b \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u0431\u0443\u0434\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u044b\u043c. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f! \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0430. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u044f\u0432\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435:<\/p>\n<pre><code class=\"cpp\">main.cpp:4:19: error: underlying type 'std::string' {aka 'std::__cxx11::basic_string&lt;char>'} of 'Color' must be an integral type     4 | enum Color : std::string { red, green, blue };       |                   ^~~~~~<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum7-specify-the-underlying-type-of-an-enumeration-only-when-necessary\">core guidelines \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443<\/a>! \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e.<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e? \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0432\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e, \u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">enum Direction : char { north, south, east, west,    northeast, northwest, southeast, southwest }; <\/code><\/pre>\n<ul>\n<li>\n<p>\u0418\u043b\u0438, \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 (forward declare) <code>enum<\/code>, \u0432\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0438 \u0442\u0438\u043f:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">enum Direction : char; void navigate(Direction d);  enum Direction : char { north, south, east, west,      northeast, northwest, southeast, southwest };<\/code><\/pre>\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u0432\u0441\u0435\u0445 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f <code>constexpr<\/code>.<\/p>\n<pre><code class=\"cpp\">enum Color : int { red = 0, green = 1, blue = 2 };<\/code><\/pre>\n<p>\u0418 \u0441\u043d\u043e\u0432\u0430 <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum8-specify-enumerator-values-only-when-necessary\">core guidelines \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e<\/a>, \u0435\u0441\u043b\u0438 \u043d\u0430 \u044d\u0442\u043e \u043d\u0435\u0442 \u043e\u0441\u043e\u0431\u043e\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438! \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u043d\u0430\u0447\u043d\u0435\u0442\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u0440\u0442\u0438\u0442\u044c. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044f.<\/p>\n<ul>\n<li>\n<p>\u0425\u043e\u0440\u043e\u0448\u0438\u043c \u044e\u0437\u043a\u0435\u0439\u0441\u043e\u043c \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0435 \u043c\u0435\u0441\u044f\u0446\u044b \u0438 \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0441 \u043d\u0443\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">enum Month { jan = 1, feb, mar, apr, may, jun,                  jul, august, sep, oct, nov, dec };<\/code><\/pre>\n<ul>\n<li>\n<p>\u0414\u0440\u0443\u0433\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">enum altitude: char {   high = 'h',   low = 'l' }; <\/code><\/pre>\n<ul>\n<li>\n<p>\u0415\u0449\u0435 \u043e\u0434\u043d\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u044d\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439. \u0422\u043e \u0435\u0441\u0442\u044c \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0434\u0432\u043e\u0439\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">enum access_type { read = 1, write = 2, exec = 4 };<\/code><\/pre>\n<h3>Scoped \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>enum<\/code> <code>EnumName{};<\/code>. \u0412 C++11 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 <code>scoped<\/code> (\u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438) <code>enum<\/code>. \u041e\u043d\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 <code>class<\/code>, \u043b\u0438\u0431\u043e <code>struct<\/code> (\u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b).<\/p>\n<p>\u0418\u0445 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">enum class Color { red, green, blue };<\/code><\/pre>\n<p>\u0414\u043b\u044f <code>scoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435, \u0438 \u044d\u0442\u043e <code>int<\/code>. \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f. \u0415\u0441\u043b\u0438 \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c <code>int<\/code>, \u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e:<\/p>\n<pre><code class=\"cpp\">enum class Color;<\/code><\/pre>\n<p>\u041d\u043e \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f, \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u0438\u0445 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f?<\/p>\n<p>Unscoped \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u044f\u0432\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u044b \u043a \u0441\u0432\u043e\u0435\u043c\u0443 \u0431\u0430\u0437\u043e\u0432\u043e\u043c\u0443 \u0442\u0438\u043f\u0443. \u041d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0438 \u0443 <code>scoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 <em>&#171;\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438&#187;<\/em>. \u0418\u043c\u0435\u043d\u043d\u043e \u0438\u0437-\u0437\u0430 \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum3-prefer-class-enums-over-plain-enums\">core guidelines \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c scoped, \u0430 \u043d\u0435 unscoped \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/a>.<\/p>\n<pre><code class=\"cpp\">void Print_color(int color);  enum Web_color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF }; enum Product_info { red = 0, purple = 1, blue = 2 };  Web_color webby = Web_color::blue;  \/\/ Clearly at least one of these calls is buggy. Print_color(webby); Print_color(Product_info::blue);<\/code><\/pre>\n<p><code>Unscoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442 \u0441\u0432\u043e\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u0438 \u0432 \u043e\u0431\u044a\u0435\u043c\u043b\u044e\u0449\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0443 \u0438\u043c\u0435\u043d. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>scoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<pre><code class=\"cpp\">enum UnscopedColor { red, green, blue }; enum class ScopedColor { red, green, blue };  int main() {     [[maybe_unused]] UnscopedColor uc = red;     \/\/ [[maybe_unused]] ScopedColor sc = red; \/\/ Doesn't compile     [[maybe_unused]] ScopedColor sc = ScopedColor::red; }<\/code><\/pre>\n<h3>\u0427\u0442\u043e \u0435\u0449\u0435?<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 <code>scoped\/unscoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0447\u0435\u043c \u043e\u043d\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u044f\u0437\u044b\u043a \u0438\u043b\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430.<\/p>\n<h4>std::is_enum<\/h4>\n<p>\u0412 C++11 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>&lt;type_traits><\/code>. \u041e\u043d \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0442\u0438\u043f\u043e\u0432. \u041d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e <code>is_enum<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0438\u043b\u0438 \u043d\u0435\u0442. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>true<\/code> \u043a\u0430\u043a \u0434\u043b\u044f <code>scoped<\/code>, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f <code>unscoped<\/code> \u0432\u0435\u0440\u0441\u0438\u0439.<\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++17, \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 <code>is_enum_v<\/code>.<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;type_traits>  enum UnscopedColor { red, green, blue }; enum class ScopedColor { red, green, blue }; struct S{};  int main() {     std::cout &lt;&lt; std::boolalpha               &lt;&lt; std::is_enum&lt;UnscopedColor>::value &lt;&lt; '\\n'               &lt;&lt; std::is_enum&lt;ScopedColor>::value &lt;&lt; '\\n'               &lt;&lt; std::is_enum_v&lt;S> &lt;&lt; '\\n'; }<\/code><\/pre>\n<h4>std::underlying_type<\/h4>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432 C++11 \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d <code>std::underlying_type<\/code>. \u041e\u043d \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0414\u043e C++20, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u043e\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u0438\u043b\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c, \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0434\u043b\u044f \u043d\u0435\u043f\u043e\u043b\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0412 C++14 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0445\u0435\u043b\u043f\u0435\u0440 <code>std::underlying_type_t<\/code>.<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;type_traits>  enum UnscopedColor { red, green, blue }; enum class ScopedColor { red, green, blue }; enum class CharBasedColor : char { red = 'r', green = 'g', blue = 'b' };  int main() {     constexpr bool isUnscopedColorInt = std::is_same_v&lt; std::underlying_type&lt;UnscopedColor>::type, int >;   constexpr bool isScopedColorInt = std::is_same_v&lt; std::underlying_type_t&lt;ScopedColor>, int >;   constexpr bool isCharBasedColorInt = std::is_same_v&lt; std::underlying_type_t&lt;CharBasedColor>, int >;   constexpr bool isCharBasedColorChar = std::is_same_v&lt; std::underlying_type_t&lt;CharBasedColor>, char >;    std::cout     &lt;&lt; \"underlying type for 'UnscopedColor' is \" &lt;&lt; (isUnscopedColorInt ? \"int\" : \"non-int\") &lt;&lt; '\\n'     &lt;&lt; \"underlying type for 'ScopedColor' is \" &lt;&lt; (isScopedColorInt ? \"int\" : \"non-int\") &lt;&lt; '\\n'     &lt;&lt; \"underlying type for 'CharBasedColor' is \" &lt;&lt; (isCharBasedColorInt ? \"int\" : \"non-int\") &lt;&lt; '\\n'     &lt;&lt; \"underlying type for 'CharBasedColor' is \" &lt;&lt; (isCharBasedColorChar ? \"char\" : \"non-char\") &lt;&lt; '\\n'     ; }<\/code><\/pre>\n<h4>\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c using \u0432 C++20<\/h4>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++20, \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>using<\/code>. \u041e\u043d \u0432\u0432\u043e\u0434\u0438\u0442 \u0438\u043c\u0435\u043d\u0430 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u0432 \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u042d\u0442\u0430 \u0444\u0438\u0447\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u043c\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c <code>using<\/code> \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438.<\/p>\n<pre><code class=\"cpp\">#include &lt;type_traits>  enum class ScopedColor { red, green, blue }; enum class CharBasedColor : char { red = 'r', green = 'g', blue = 'b' };  int main() {   using enum ScopedColor; \/\/ OK!   using enum CharBasedColor; \/\/ error: 'CharBasedColor CharBasedColor::red' conflicts with a previous declaration }<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432 <code>unscoped<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0435\u043d. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0437 <code>UnscopedColor<\/code> \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b <code>red<\/code>, <code>green<\/code> \u0438 <code>blue<\/code>, \u043e\u0434\u043d\u0430\u043a\u043e <code>using<\/code> <code>ScopedColor<\/code> \u0441 \u0442\u0435\u043c\u0438 \u0436\u0435 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"cpp\">#include &lt;type_traits>  enum UnscopedColor { red, green, blue }; enum class ScopedColor { red, green, blue };  int main() {   using enum ScopedColor; }<\/code><\/pre>\n<h4>C++23 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 std::is_scoped_enum<\/h4>\n<p>\u0412 C++23 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 <code>&lt;type_traits><\/code> \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438, \u2014 <code>std::is_scoped_enum<\/code> \u0438 \u0435\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>std::is_scoped_enum_v<\/code>. \u041a\u0430\u043a<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-363405","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/363405","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=363405"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/363405\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=363405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=363405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=363405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}