{"id":469053,"date":"2025-07-30T15:00:07","date_gmt":"2025-07-30T15:00:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=469053"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=469053","title":{"rendered":"<span>\u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0430\u044f \u0421++ \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432: \u0434\u043b\u044f Qt \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e<\/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<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3e6\/b4f\/05e\/3e6b4f05ea57d8f495af28a6b3518976.png\" width=\"1280\" height=\"720\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/3e6\/b4f\/05e\/3e6b4f05ea57d8f495af28a6b3518976.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3e6\/b4f\/05e\/3e6b4f05ea57d8f495af28a6b3518976.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041c\u0438\u0445\u0430\u0438\u043b \u041f\u043e\u043b\u0443\u043a\u0430\u0440\u043e\u0432, \u044f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 Desktop-\u0432\u0435\u0440\u0441\u0438\u0438 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0441\u0443\u043f\u0435\u0440\u0430\u043f\u043f\u0430 \u0434\u043b\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b <a href=\"https:\/\/biz.mail.ru\/teams\/?utm_source=habr&amp;utm_medium=refferal&amp;utm_campaign=fabrica_dlya_std\" rel=\"noopener noreferrer nofollow\">VK Teams<\/a>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438, \u0433\u0434\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Factory Method \u0438\u043b\u0438 AbstractFactory. \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u044f \u043d\u0435\u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u043b\u043e\u0432\u0438\u043b \u0441\u0435\u0431\u044f \u043d\u0430 \u043c\u044b\u0441\u043b\u0438, \u0447\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u043f\u0438\u0448\u0443 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0439 \u043a\u043e\u0434 \u0442\u0430\u043a\u0438\u0445 \u0444\u0430\u0431\u0440\u0438\u043a, \u0438 \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u0441\u0430\u043c\u043e\u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439.\u00a0<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c DRY (Don\u2019t Repeat Yourself), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u00ab\u0444\u0438\u0448\u043a\u0438\u00bb \u043d\u043e\u0432\u044b\u0445 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432 \u0421++.\u00a0<\/p>\n<blockquote>\n<p><strong><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: <\/em><\/strong><em>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <\/em><a href=\"https:\/\/github.com\/progzdeveloper\/HabrQtDemos\/tree\/main\/ObjectFactory\" rel=\"noopener noreferrer nofollow\"><em>\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 GitHub<\/em><\/a><em>. \u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 C++17 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Qt, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0441\u0442\u0435\u043a.<\/em><\/p>\n<\/blockquote>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0424\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0430\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c\u0438 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u0440\u0438\u0447\u0438\u043d \u044d\u0442\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0432 C++ \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0432 \u044f\u0437\u044b\u043a \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u00ab\u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e\u00bb \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432: \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0435\u0441\u0442\u044c, \u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u0436\u0435 (\u0438\u043b\u0438 \u043f\u043e\u0445\u043e\u0436\u0435\u0433\u043e) \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u2014 \u043d\u0435\u0442. \u0421\u0432\u044f\u0437\u0430\u043d\u043e \u044d\u0442\u043e \u0441\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432 \u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u0430\u043c\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430, \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0434\u0430\u043b\u0435\u043a\u043e \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.\u00a0<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0438\u0437 \u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430: \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0432 \u0442\u043e\u0439 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0438\u0448\u0435\u0442\u0435 \u043a\u043e\u0434 \u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u0442\u0438\u043f\u043e\u0432, \u0442\u043e \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0434\u043e\u043b\u0435\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u044b\u043b \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u044b\u043c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043f\u0435\u0440\u0432\u0430 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">class Shape { public: \u00a0\u00a0\u00a0\u00a0virtual ~Shape() = default; \u00a0\u00a0\u00a0\u00a0\/\/ ... };  class Circle : public Shape { ... }; class Rectangle : public Shape { ... }; class Line : public Shape { ... };<\/code><\/pre>\n<h3>Dummy Factory<\/h3>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u0438. \u041e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">class ShapeFactory { \u00a0\u00a0\u00a0\u00a0class Creator \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual ~Creator() = default; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual Shape* create() const = 0; \u00a0\u00a0\u00a0\u00a0};  \u00a0\u00a0\u00a0\u00a0template&lt;class _Shape&gt; \u00a0\u00a0\u00a0\u00a0class ShapeCreator : public Creator \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual Shape* create() const override \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return new _Shape; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0}; \u00a0\u00a0\u00a0\u00a0using CreatorPointer = std::unique_ptr&lt;Creator&gt;;  public: \u00a0\u00a0\u00a0\u00a0\u00a0template&lt;class _Shape&gt; \u00a0\u00a0\u00a0\u00a0\u00a0void registrate(const std::string&amp; key) \u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert(std::is_base_of_v&lt;Shape, Shape&gt;, \"Shape must be derived from Shape\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto[it, inserted] = creators_.emplace(key, {}); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (inserted) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0it-&gt;second.reset(new Creator&lt;_Shape&gt;); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Shape* createShape(const std::string&amp; key) const \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto it = creators_.find(key); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return it != creators_.end() ? it-&gt;second-&gt;create() : nullptr; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}  private: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0std::unordered_map&lt;std::string, CreatorPointer&gt; creators_; };<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c: \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u043d\u0435\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Creator \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0431\u0435\u0437 \u043e\u0441\u043e\u0431\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0442\u0430\u043a \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0443:<\/p>\n<pre><code class=\"cpp\">ShapeFactory factory; factory.registrate&lt;Circle&gt;(\"cirlce\"); factory.registrate&lt;Rectangle&gt;(\"rectanle\"); factory.registrate&lt;Line&gt;(\"line\"); factory.registrate&lt;MyShape&gt;(\"myshape\"); \/\/ \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0444\u0438\u0433\u0443\u0440\u044b std::vector&lt;std::unique_ptr&lt;Shape&gt;&gt; shapes; shapes.emplace_back(factory.create(\"circle\")); shapes.emplace_back(factory.create(\"rectangle\")); \/\/ ... \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435<\/code><\/pre>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e: \u043d\u0443\u0436\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f, \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u043e\u0434 \u0438 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0435\u0433\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::function&lt;&gt; \u0432\u043c\u0435\u0441\u0442\u043e Creator \u0438 ShapeCreator&lt;_Shape&gt;. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u043c\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>\u043e\u0442 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u2014 std::function&lt;&gt; \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c pointer-semantic \u043d\u0430 value-semantic, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u0441\u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e;<\/p>\n<\/li>\n<li>\n<p>\u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0432 heap \u2014 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 std::function&lt;&gt; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Small-Value-Optimization;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u2014 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u043e\u0442\u043e\u043a \u0438 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0435\u043d.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0440\u043e\u043c\u0435 \u043f\u0440\u043e\u0447\u0435\u0433\u043e, \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">class ShapeFactory { public: \u00a0\u00a0\u00a0\u00a0using Creator = std::function&lt;Shape*()&gt;;  \u00a0\u00a0\u00a0\u00a0template&lt;class _Shape&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const std::string&amp; key, const Creator&amp; c) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert(std::is_base_of_v&lt;Shape, Shape&gt;, \u201cShape must be derived from Shape\u201d); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = c; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0template&lt;class _Shape&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const std::string&amp; key) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert(std::is_base_of_v&lt;Shape, Shape&gt;, \u201cShape must be derived from Shape\u201d); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = []() -&gt; Shape* { return new _Shape; }; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0Shape* createShape(const std::string&amp; key) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto it = creators_.find(key); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return it != creators_.end() ? (it-&gt;second)() : nullptr; \u00a0\u00a0\u00a0\u00a0}  private: \u00a0\u00a0\u00a0\u00a0\u00a0std::unordered_map&lt;std::string, Creator&gt; creators_; };<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e:<\/p>\n<ul>\n<li>\n<p>\u0422\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0435\u0433\u043e \u0441\u043c\u0435\u043d\u0438\u0442\u044c, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u044f\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0438\u0445 \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u0447\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0422\u0438\u043f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0432\u0441\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u0441 \u043d\u0443\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438 \u043a Generic Factory<\/h3>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0442\u044c \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0412\u044b\u0434\u0435\u043b\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e:<\/p>\n<ul>\n<li>\n<p>\u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u0432\u043d\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0442\u0438\u043f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u0432\u043d\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0442\u0438\u043f\u044b \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u0432\u043d\u0435;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0443\u0436\u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 RTTI;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Qt \u0438 Qt Meta-Object System.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u0443\u0434\u0435\u043c \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u0443\u043d\u043a\u0442\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<h4>\u0422\u0438\u043f\u044b \u043a\u043b\u044e\u0447\u0430 \u0438 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u043f\u0443\u043d\u043a\u0442\u0430 \u043f\u0440\u043e\u0441\u0442\u044b \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u043c:<\/p>\n<pre><code class=\"cpp\">template&lt; \u00a0\u00a0\u00a0\u00a0class _Key, \/\/ \u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u00a0\u00a0\u00a0\u00a0class _Base \/\/ \u0442\u0438\u043f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 &gt; class ObjectFactory { public: \u00a0\u00a0\u00a0\u00a0using Creator = std::function&lt;_Base*()&gt;;  \u00a0\u00a0\u00a0\u00a0template&lt;class _Product&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const _Key&amp; key, const Creator&amp; c) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert(std::is_base_of_v&lt;_Base, Product&gt;, \"Product must be derived from _Base\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = c; \u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0     template&lt;class _Product&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const _Key&amp; key) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert(std::is_base_of_v&lt;_Base, Product&gt;, \"Product must be derived from _Base\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = []() -&gt; Base* { return new Product; }; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0_Base* createShape(const Key&amp; key) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto it = creators_.find(key); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return it != creators_.end() ? (it-&gt;second)() : nullptr; \u00a0\u00a0\u00a0\u00a0}  private: \u00a0\u00a0\u00a0\u00a0std::unordered_map&lt;_Key, Creator&gt; creators_; };<\/code><\/pre>\n<p>\u0421\u0430\u043c \u043a\u043e\u0434 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u0440\u043f\u0435\u043b \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Shape, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435:<\/p>\n<pre><code class=\"cpp\">using ShapeFactory = ObjectFactory&lt;QString, Shape&gt;;<\/code><\/pre>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0443\u043d\u043a\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c, \u043d\u043e \u0442\u0443\u0442-\u0442\u043e \u0438 \u0442\u0430\u0438\u0442\u0441\u044f \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430.\u00a0<\/p>\n<h4>\u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0438\u0445 \u0442\u0438\u043f\u044b<\/h4>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430: \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c variadic template \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0448\u0430\u0431\u043b\u043e\u043d \u043a\u043b\u0430\u0441\u0441\u0430 ObjectFactory:<\/p>\n<pre><code class=\"cpp\">template&lt; \u00a0\u00a0\u00a0\u00a0class _Key, \/\/ \u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u00a0\u00a0\u00a0\u00a0class _Base, \/\/ \u0442\u0438\u043f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u00a0\u00a0\u00a0\u00a0class... _Args \/\/ \u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 &gt; class ObjectFactory { public: \u00a0\u00a0\u00a0\u00a0using Creator = std::function&lt;_Base*(_Args&amp;&amp;...)&gt;;  \u00a0\u00a0\u00a0\u00a0template&lt;class _Product&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const _Key&amp; key, const Creator&amp; c) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert (std::is_base_of_v&lt;_Base, Product&gt;, \"Product must inherited from _Base\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = c; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0template&lt;class _Product&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const _Key&amp; key) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert (std::is_base_of_v&lt;_Base, Product&gt;, \"Product must inherited from _Base\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = [](_Args&amp;&amp;... args) { return new Product(std::forward&lt;Args&gt;(args)...); }; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0Base* create(const Key&amp; key, _Args&amp;&amp;... args) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto it = creators_.find(key); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return it != creators_.cend() ? (it-&gt;second)(std::forward&lt;_Args&gt;(args)...) : nullptr; \u00a0\u00a0\u00a0\u00a0}  private: \u00a0\u00a0\u00a0\u00a0std::unordered_map&lt;_Key, Creator&gt; creators_; };<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0445\u043e\u0434 \u0432\u043f\u043e\u043b\u043d\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u2014 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u041d\u043e \u0437\u0430\u0433\u0432\u043e\u0437\u0434\u043a\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u0443 \u0432\u0441\u0435\u0445 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430. \u041a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430, \u0442\u0430\u043a \u0431\u044b\u0432\u0430\u0435\u0442 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u2014 \u0421++ \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c, \u0441\u043a\u0430\u0436\u0435\u043c, \u043d\u0430 QPushButton:<\/p>\n<pre><code class=\"cpp\">explicit QPushButton(QWidget *parent = nullptr); explicit QPushButton(const QString &amp;text, QWidget *parent = nullptr); QPushButton(const QIcon&amp; icon, const QString &amp;text, QWidget *parent = nullptr);<\/code><\/pre>\n<p>\u0421 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u0432\u044b\u0439\u0434\u0435\u0442.<\/p>\n<h3>\u041f\u0440\u044b\u0436\u043e\u043a \u0432 \u043a\u0440\u043e\u043b\u0438\u0447\u044c\u044e \u043d\u043e\u0440\u0443<\/h3>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0432\u0441\u0435 \u043c\u043e\u0438 \u043c\u044b\u0442\u0430\u0440\u0441\u0442\u0432\u0430 \u043f\u043e \u043f\u043e\u0438\u0441\u043a\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043d\u043e \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e: \u043a\u0440\u043e\u043b\u0438\u0447\u044c\u044f \u043d\u043e\u0440\u0430 \u0433\u043b\u0443\u0431\u043e\u043a\u0430.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043f\u043e\u0447\u0442\u0438 \u0441\u0440\u0430\u0437\u0443: \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441\u0442\u0430\u043b\u043e \u043a\u0440\u0430\u0442\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435. \u041c\u0430\u043b\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u044f\u0441\u043d\u043e, \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043e\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0438 \u0434\u043b\u044f \u0432\u0430\u0440\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u0430\u043a \u0435\u0449\u0435 \u0438 \u043d\u0435 \u044f\u0441\u043d\u043e, \u043a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.\u00a0<\/p>\n<p>\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441-\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u043a\u043b\u044e\u0447?\u00a0<\/p>\n<p>\u0423\u0445\u0438\u0449\u0440\u0435\u043d\u0438\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u043d\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043c\u0435\u0442\u0430\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0442\u0438\u043f\u0430\u0445. \u0412\u0441\u0435 \u0438\u0434\u0435\u0438 \u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0432\u043e\u043a\u0440\u0443\u0433 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u043a-\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0440\u0442\u0435\u0436 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.\u00a0<\/p>\n<p>\u041a\u0430\u043a \u0432\u0430\u0440\u0438\u0430\u043d\u0442: \u0441\u043e\u0437\u0434\u0430\u0442\u044c std::tuple&lt;_Args&#8230;&gt; \u0438 \u0432\u0437\u044f\u0442\u044c \u043e\u0442 \u043d\u0435\u0433\u043e typeid. \u041d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b RTTI, \u0447\u0435\u0433\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c. \u0422\u0443\u0442 \u043d\u0430\u043c \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Qt \u0438 \u0435\u0435 \u043c\u0435\u0442\u0430\u043e\u0431\u044a\u0435\u043a\u0442\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0438\u0448\u043a\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430 C++. \u0418\u0434\u0435\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 qMetaTypeId&lt;T&gt; \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0442\u0438\u043f\u0430.\u00a0<\/p>\n<blockquote>\n<p><strong><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: <\/em><\/strong><em>\u0415\u0441\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Qt \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 qMetaTypeId&lt;T&gt;. \u0420\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u043c\u043e\u0435\u0439 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 <\/em><a href=\"https:\/\/habr.com\/ru\/companies\/vk\/articles\/810085\/\" rel=\"noopener noreferrer nofollow\"><em>\u0441\u0442\u0430\u0442\u044c\u0435<\/em><\/a><em>.<\/em><\/p>\n<\/blockquote>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f std::function, \u0442\u0435\u0445\u043d\u0438\u043a\u0443 type-erasure (\u00ab\u0441\u0442\u0438\u0440\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u0430\u00bb) \u0438 \u043e\u043f\u0438\u0441\u0430\u0432 \u043a\u043b\u0430\u0441\u0441-\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c, \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441\u044b-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438. \u041f\u043e\u0434\u0443\u043c\u0430\u0432 (\u043d\u0435 \u0431\u0443\u0434\u0443 \u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c, \u0434\u0443\u043c\u0430\u0442\u044c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0433\u043e), \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0439\u0442\u0438 \u043a \u0442\u0430\u043a\u043e\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044e:<\/p>\n<pre><code class=\"cpp\">struct Creator { \u00a0\u00a0\u00a0\u00a0_Key key; \/\/ \u043a\u043b\u044e\u0447\u00a0 \u00a0\u00a0\u00a0\u00a0const int* argv = nullptr; \/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0438\u043f\u043e\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u00a0\u00a0\u00a0\u00a0int argc = 0; \/\/ \u0447\u0438\u0441\u043b\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u00a0\u00a0\u00a0\u00a0const void* ptr = nullptr; \/\/\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e \u00ab\u0441\u0442\u0435\u0440\u0442\u044b\u043c\u00bb \u0442\u0438\u043f\u043e\u043c (void*)  \u00a0\u00a0\u00a0\u00a0\/\/\u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u0430 \u0442\u0438\u043f\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f (\u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430) \u00a0\u00a0\u00a0\u00a0template&lt;class... _Args&gt; \u00a0\u00a0\u00a0\u00a0using CreatorFunction = std::function&lt;_Base*(_Args&amp;&amp;...)&gt;;  \u00a0\u00a0\u00a0\u00a0template&lt;class Product, class... Args&gt; \u00a0\u00a0\u00a0\u00a0static Creator make(const _Key&amp; k) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0447\u0438\u0441\u043b\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static constexpr int kArgsCount = sizeof...(_Args); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e qMetaTypeId\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static const int kArgsMeta[sizeof...(_Args)] = { qMetaTypeId&lt;_Args&gt;()... }; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u043d\u0430\u044f \u0432 std::function \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static const CreatorFunction&lt;_Args...&gt; p = [](_Args&amp;&amp;... args) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return new Product(std::forward&lt;Args&gt;(args)...);\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return { k, kArgsMeta, kArgsCount, &amp;p }; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0\/\/\u0442\u043e \u0436\u0435, \u0447\u0442\u043e \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0448\u0435, \u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 (\u0431\u0435\u0437 \u0432\u0437\u044f\u0442\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e) \u00a0\u00a0\u00a0\u00a0template&lt;class... _Args&gt; \u00a0\u00a0\u00a0\u00a0static Creator id(const _Key&amp; k) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static constexpr int kArgsCount = sizeof...(_Args); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static const int kArgsMeta[sizeof...(_Args)] = { qMetaTypeId&lt;_Args&gt;()... }; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return { k, kArgsMeta, kArgsCount, nullptr }; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0template&lt;class... _Args&gt; \u00a0\u00a0\u00a0\u00a0Base* create(Args&amp;&amp;... args) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 (\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e) \u0438 \u0432\u044b\u0437\u043e\u0432 \u043b\u044f\u043c\u0431\u0434\u044b \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return (*(static_cast&lt;const CreatorFunction&lt;_Args...&gt;*&gt;(ptr)))(std::forward&lt;_Args&gt;(args)...); \u00a0\u00a0\u00a0\u00a0} };<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0442\u0440\u044e\u043a\u043e\u0432.\u00a0<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u0430 \u0442\u0438\u043f\u0430. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0442\u0438\u043f std::function&lt;&#8230;&gt; \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u0440\u044e\u043a \u2014 \u00ab\u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435\u00bb \u0432\u0430\u0440\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 (variadic template parameter pack unfolding):<\/p>\n<pre><code class=\"cpp\">static const int kArgsMeta[sizeof...(_Args)] = { qMetaTypeId&lt;_Args&gt;()... };<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435: qMetaTypeId&lt;T&gt; \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0442\u0438\u043f\u0430, \u043d\u0435 \u043f\u0440\u0438\u0431\u0435\u0433\u0430\u044f \u043a \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430\u043c RTTI, \u0430 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u2014 \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u043d\u0430\u0439\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 Creator \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u0444\u0430\u0431\u0440\u0438\u043a\u0443.<\/p>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, type-erasure.<\/p>\n<pre><code class=\"cpp\">\/\/ \u0431\u0435\u0440\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 std::function \u043a\u0430\u043a const void*\u00a0 \/\/ (\u044f\u0432\u043d\u044b\u0439 \u043a\u0430\u0441\u0442 \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d) return { k, kArgsMeta, kArgsCount, &amp;p };\u00a0  \/\/ \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 (\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e) \u0438 \u0432\u044b\u0437\u043e\u0432\u00a0 \/\/ (\u044f\u0432\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e) return (*(static_cast&lt;const CreatorFunction&lt;_Args...&gt;*&gt;(ptr)))(std::forward&lt;_Args&gt;(args)...);<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u0442\u0435\u0445\u043d\u0438\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0430 \u043d\u0430\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e \u0442\u0438\u043f\u0443 std::function, \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u0440\u0436\u0430 const void* \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0430\u043c\u043e\u0439 std::function. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u044d\u0442\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b std::function \u2014 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043c\u0435\u043d\u044f\u044e\u0442 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u044b \u041c\u0435\u0439\u0435\u0440\u0441\u0430 \u0432 \u043c\u0438\u043d\u0438\u0430\u0442\u044e\u0440\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">template&lt;class Key, class Base&gt; class ObjectFactory { \u00a0\u00a0\u00a0\u00a0class Creator { ... }; \/\/ \u043a\u0430\u043a \u0438 \u0432\u044b\u0448\u0435 \u2014 \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439  \u00a0\u00a0\u00a0\u00a0\/\/ \u0424\u0443\u043d\u043a\u0442\u043e\u0440 \u0445\u0435\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b Creator \u00a0\u00a0\u00a0\u00a0struct CreatorHash \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0inline size_t operator()(const Creator&amp; id) const noexcept \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c QHashCombine\u0438 qHashRange \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return QtPrivate::QHashCombine{}(qHashRange(id.argv, id.argv + id.argc), id.key); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0};  \u00a0\u00a0\u00a0\u00a0\/\/ \u0424\u0443\u043d\u043a\u0442\u043e\u0440 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b Creator \u00a0\u00a0\u00a0\u00a0struct CreatorMatch \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0inline bool operator()(const Creator&amp; lhs, const Creator&amp; rhs) const noexcept \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (lhs.argc != rhs.argc || lhs.key != rhs.key) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return false; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (lhs.argv &amp;&amp; rhs.argv) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return memcmp(lhs.argv, rhs.argv, lhs.argc) == 0; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return (!lhs.argv &amp;&amp; !rhs.argv); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0};  \/\/ \u0422\u0438\u043f \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e\u0438\u0441\u043a\u0430 using CreatorsMap = std::unordered_set&lt;Creator, CreatorHash, CreatorMatch&gt;;  public: \u00a0\u00a0\u00a0\u00a0template&lt;class Product, class... Args&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const _Key&amp; k) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u2014 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e template \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_.emplace(Creator::template make&lt;_Product, _Args...&gt;(k)); \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0template&lt;class... _Args&gt; \u00a0\u00a0\u00a0\u00a0Base* create(const Key&amp; k, _Args... args) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 std::decay_t&lt;_Args&gt;... \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto it = creators_.find(Creator::template id&lt;std::decay_t&lt;_Args&gt;...&gt;(k)); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (it == creators_.end()) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return nullptr; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return it-&gt;create(std::forward&lt;_Args&gt;(args)...); \u00a0\u00a0\u00a0\u00a0}  private: \u00a0\u00a0\u00a0\u00a0CreatorsMap creators_; };<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043f\u0440\u0438\u0435\u043c\u044b.\u00a0<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0438\u043c\u0435\u043d QtPrivate \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 QHashCombine, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u043f\u043e \u0441\u0443\u0442\u0438, \u043a\u0430\u043b\u044c\u043a\u043e\u0439 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 boost \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u0435\u0448-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f qHashRange() \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 Qt \u0438\u0437 boost \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.\u00a0<\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 template \u0432 \u043c\u0435\u0441\u0442\u0430\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 Creator::make() \u0438 Creator::id(). \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443 C++, \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 template, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0438\u043c\u0435\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0439.\u00a0<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 std::decay_t. \u042d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 type trait, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u00ab\u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0435\u00bb \u0442\u0438\u043f\u044b. \u0412\u0430\u0436\u043d\u043e \u044d\u0442\u043e \u0438\u0437-\u0437\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 C++. \u0417\u0434\u0435\u0441\u044c \u0434\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0432\u044b\u0432\u043e\u0434\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0442\u0438\u043f \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e; \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u00ab\u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c\u00bb \u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043e\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432 \u044d\u0442\u043e\u0442 \u0442\u0438\u043f \u043f\u043e\u043f\u0430\u0441\u0442\u044c. \u0415\u0441\u043b\u0438 \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::decay_t, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0435 \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441-\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 qMetaTypeId&lt;T&gt; \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>\u041a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u044b\u043c, \u0438 \u043d\u0443\u0436\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442. \u041d\u043e \u0435\u0441\u0442\u044c \u0443 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0440\u044f\u0434 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u0430\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438 void* \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 type cast, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0437\u043e\u0432 \u043d\u0430 \u043d\u0435\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435 (\u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u0437-\u0437\u0430 type erasure \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u043d\u0430\u043c\u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0441 \u0442\u043e\u0439, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435).<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u0432\u0437\u044f\u0442\u043e\u0433\u043e \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043d\u0430 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430 \u0421++11 \u043e\u043d\u0438 \u043d\u0435\u044f\u0432\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (\u0441\u043c. \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d \u041c\u0435\u0439\u0435\u0440\u0441\u0430).<\/p>\n<\/li>\n<\/ul>\n<h3>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/h3>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434, \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u2014 \u0443\u0431\u0440\u0430\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438.<\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b-\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0438 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f std::function. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u0445\u0432\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0437\u0430 \u00ab\u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<pre><code class=\"cpp\">class CreatorBase { public: \u00a0\u00a0\u00a0\u00a0CreatorBase(const Key&amp; k) : key(k) {} \u00a0\u00a0\u00a0\u00a0virtual ~CreatorBase() = default; \u00a0\u00a0\u00a0\u00a0const Key&amp; key() const { return key; }  \u00a0\u00a0\u00a0\u00a0template&lt;class... _Args&gt; \u00a0\u00a0\u00a0\u00a0virtual Base* create(Args&amp;&amp;... args) = 0; \/\/ OOPS! Can\u2019t compile! private: \u00a0\u00a0\u00a0\u00a0Key key; };<\/code><\/pre>\n<p>\u0423\u0432\u044b, \u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u2014 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u043c\u0438. \u041f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u2014 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0443\u0434\u0430\u0441\u0442\u0441\u044f \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044f \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a:<\/p>\n<pre><code class=\"cpp\">class CreatorBase { public: \u00a0\u00a0\u00a0\u00a0CreatorBase(const Key&amp; k) : key(k) {} \u00a0\u00a0\u00a0\u00a0const Key&amp; key() const { return key; } \u00a0\u00a0\u00a0\u00a0virtual ~CreatorBase() = default; private: \u00a0\u00a0\u00a0\u00a0Key key; };  template&lt;class Product, class... Args&gt; class Creator : public CreatorBase { public: \u00a0\u00a0\u00a0\u00a0Creator(const _Key&amp; k) : CreatorBase(k) {} \u00a0\u00a0\u00a0\u00a0Base* create(Args&amp;&amp;... args) const\u00a0 \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return new Product(std::forward&lt;Args&gt;(args)...)); \u00a0\u00a0\u00a0\u00a0} };<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0443\u0436\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u043d\u043e \u043a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0437\u0432\u0430\u0442\u044c Creator::create()? \u0418\u0437-\u0437\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 _Product \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u043d\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 (\u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432), \u043d\u043e \u044d\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043a\u0440\u044b\u0442\u044c!<\/p>\n<h3>\u041a\u043b\u0430\u0441\u0441\u044b Intermezzo<\/h3>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043b\u0430\u0441\u0441 \u00ab\u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435\u00bb. \u041c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 Intermezzo Class (\u043e\u0442 \u0438\u0442\u0430\u043b. intermezzo \u2014 \u0441\u0440\u0435\u0434\u043d\u0438\u0439, \u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435).\u00a0<\/p>\n<p>\u0418\u0434\u0435\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043b\u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0443\u0436\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a. \u0412 \u043a\u043e\u0434\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">\/\/ Creator base class class CreatorBase { public: \u00a0\u00a0\u00a0\u00a0CreatorBase(const Key&amp; k) : key(k) {} \u00a0\u00a0\u00a0\u00a0virtual ~CreatorBase() = default; \u00a0\u00a0\u00a0\u00a0const Key&amp; key() const { return key; } private: \u00a0\u00a0\u00a0\u00a0Key key; };  \/\/ Intermezzo Class template&lt;class... _Args&gt;\u00a0 class ClassCreator : public CreatorBase { public: \u00a0\u00a0\u00a0\u00a0ClassCreator(const _Key&amp; k) : CreatorBase(k) {} \u00a0\u00a0\u00a0\u00a0virtual Base* create(Args&amp;&amp;... args) const = 0; };   \/\/ Concrete Product Creator template&lt;class Product, class... Args&gt; class Creator : public ClassCreator&lt;_Args...&gt; { public: \u00a0\u00a0\u00a0\u00a0Creator(const Key&amp; k) : ClassCreator&lt;Args...&gt;(k) {} \u00a0\u00a0\u00a0\u00a0Base* create(Args&amp;&amp;... args) const override \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return new Product(std::forward&lt;Args&gt;(args)...); \u00a0\u00a0\u00a0\u00a0} };<\/code><\/pre>\n<p>\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c intermezzo \u043a\u043b\u0430\u0441\u0441\u0430 \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0435\u0433\u043e \u0442\u0438\u043f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0432\u0430\u0440\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043d\u043e \u043c\u0430\u0441\u043a\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c, \u043a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 _Base. \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0443\u0436\u0435 \u0438\u0441\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430, \u0441 \u0442\u043e\u0439 \u043b\u0438\u0448\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0435\u0439, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0432\u0435\u0441\u0442\u0438 \u043c\u0435\u0442\u043e\u0434 isMatched() \u0438 \u043f\u0430\u0440\u0443 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435-\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0435:<\/p>\n<pre><code class=\"cpp\">\/\/Creator base class class CreatorBase { public: \u00a0\u00a0\u00a0\u00a0CreatorBase(const Key&amp; k) : key(k) {} \u00a0\u00a0\u00a0\u00a0virtual ~CreatorBase() = default; \u00a0\u00a0\u00a0\u00a0\/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0442\u0438\u043f\u043e\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u00a0\u00a0\u00a0\u00a0virtual const int* argsMeta() const { return nullptr; } \u00a0\u00a0\u00a0\u00a0\/\/\u0447\u0438\u0441\u043b\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u00a0\u00a0\u00a0\u00a0virtual int argsCount() const { return 0; } \u00a0\u00a0\u00a0\u00a0\/\/\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043b\u044e\u0447 \u0442\u0438\u043f\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u00a0\u00a0\u00a0\u00a0const Key&amp; key() const { return key; } \u00a0\u00a0\u00a0\u00a0\/\/\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0442\u0438\u043f\u043e\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u00a0\u00a0\u00a0\u00a0bool isMatched(const _Key&amp; k, const int* args, int n) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (k != key_ || n != argsCount()) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return false;  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (args &amp;&amp; argsMeta()) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return memcmp(args, argsMeta(), n) == 0; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return (!args &amp;&amp; !argsMeta()); } private: \u00a0\u00a0\u00a0\u00a0Key key; };<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0435\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">\/\/ Intermezzo Class template&lt;class... _Args&gt;\u00a0 class ClassCreator : public CreatorBase { \u00a0\u00a0\u00a0\u00a0static constexpr int kArgsCount = sizeof...(_Args); \u00a0\u00a0\u00a0\u00a0static const int kArgsMeta[sizeof...(_Args)]; public: \u00a0\u00a0\u00a0\u00a0ClassCreator(const _Key&amp; k) : CreatorBase(k) {}  \u00a0\u00a0\u00a0\u00a0const int* argsMeta() const override { return kArgsMeta; } \/\/ reimp fromCreatorBase \u00a0\u00a0\u00a0\u00a0int argsCount() const override { return kArgsCount; } \/\/ reimp fromCreatorBase \u00a0\u00a0\u00a0\u00a0virtual Base* create(Args&amp;&amp;... args) const = 0; };  \/\/ Concrete Product Creator template&lt;class Product, class... Args&gt; class Creator : public ClassCreator&lt;_Args...&gt; { public: \u00a0\u00a0\u00a0\u00a0Creator(const Key&amp; k) : ClassCreator&lt;Args...&gt;(k) {} \u00a0\u00a0\u00a0\u00a0Base* create(Args&amp;&amp;... args) const override \/\/ reimp from ClassCreator&lt;_Args...&gt; \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return new Product(std::forward&lt;Args&gt;(args)...); \u00a0\u00a0\u00a0\u00a0} };<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0443\u0431\u043e\u0434\u0440\u043e\u0431\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"cpp\">template&lt;class Key, class Base&gt; template&lt;class... _Args&gt; const int ObjectFactory&lt;_Key, Base&gt;::ClassCreator&lt;Args...&gt;::kArgsMeta[sizeof...(_Args)] = { qMetaTypeId&lt;_Args&gt;()... };<\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043a\u0438\u0434\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430-\u0444\u0430\u0431\u0440\u0438\u043a\u0438:<\/p>\n<pre><code class=\"cpp\">template&lt; \u00a0\u00a0\u00a0\u00a0class _Key, \/\/ \u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u00a0\u00a0\u00a0\u00a0class _Base \/\/ \u0442\u0438\u043f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 &gt; class ObjectFactory { \u00a0\u00a0\u00a0\u00a0\/\/ \u041a\u043b\u0430\u0441\u0441\u044b CreatorBase, ClassCreator, Creator \u043a\u0430\u043a \u0438 \u0432\u044b\u0448\u0435 \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u00a0\u00a0\u00a0\u00a0class CreatorBase { ... } \u00a0\u00a0\u00a0\u00a0\/\/ Intermezzo Class \u00a0\u00a0\u00a0\u00a0template&lt;class... _Args&gt;\u00a0 \u00a0\u00a0\u00a0\u00a0class ClassCreator : public CreatorBase { ... }; \u00a0\u00a0\u00a0\u00a0\/\/ Concrete Product Creator \u00a0\u00a0\u00a0\u00a0template&lt;class Product, class... Args&gt; \u00a0\u00a0\u00a0\u00a0class Creator : public ClassCreator&lt;_Args...&gt; { ... };  \u00a0\u00a0\u00a0\u00a0using CreatorPointer = std::unique_ptr&lt;CreatorBase&gt;; \u00a0\u00a0\u00a0\u00a0using CreatorStorage = std::vector&lt;CreatorPointer&gt;;  public: \u00a0\u00a0\u00a0\u00a0template&lt;class Product, class... Args&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const _Key&amp; key) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert (std::is_base_of_v&lt;_Base, Product&gt;, \"Product must be derived from _base type\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static constexpr int argc = sizeof...(_Args); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static const int argv[] = { qMetaTypeId&lt;_Args&gt;()... }; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (const auto&amp; c : std::as_const(creators_)) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (c-&gt;isMatched(key, argv, argc)) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_.push_back(std::make_unique&lt;Creator&lt;_Product, _Args...&gt;&gt;(key)); \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0template&lt;class... _Args&gt; \u00a0\u00a0\u00a0\u00a0Base* create(const Key&amp; key, _Args... args) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0using CreatorType = ClassCreator&lt;_Args...&gt;; \/\/ \u0442\u0438\u043fintermezzo \u043a\u043b\u0430\u0441\u0441\u0430 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static constexpr int argc = sizeof...(_Args); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static const int argv[] = { qMetaTypeId&lt;std::decay_t&lt;_Args&gt;&gt;()... }; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (const auto&amp; c : creators_) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (c-&gt;isMatched(key, argv, argc)) \/\/ \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 \u043a intermezzo \u043a\u043b\u0430\u0441\u0441\u0443 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const CreatorType* creator = static_cast&lt;const CreatorType*&gt;(c.get()); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f perfect forwarding \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return creator-&gt;create(std::forward&lt;_Args&gt;(args)...); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return nullptr; \u00a0\u00a0\u00a0\u00a0} private: \u00a0\u00a0\u00a0\u00a0CreatorStorage creators_; };  \/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0442\u0438\u043f\u043e\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 template&lt;class Key, class Base&gt; template&lt;class... _Args&gt; const int ObjectFactory&lt;_Key, Base&gt;::ClassCreator&lt;Args...&gt;::kArgsMeta[sizeof...(_Args)] = { qMetaTypeId&lt;_Args&gt;()... };<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0437\u0434\u0435\u0441\u044c std::vector, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 std::unordered_map(_set) \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u043a\u043e\u0434 \u0438 \u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446 \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f.\u00a0<\/p>\n<p>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0443\u0431\u0440\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><s>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u0430\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c<\/s>. \u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442 void* \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e.<\/p>\n<\/li>\n<li>\n<p><s>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043d\u0430 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b.<\/s> \u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0425\u043c-\u043c, \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u0443\u043d\u043a\u0442\u043e\u0432 \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0442, \u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f \u043d\u0430\u0434 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 STL.\u00a0<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u043b\u0435\u0447\u0435\u043c\u0441\u044f \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u0432 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u0442\u0430 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f.<\/p>\n<h3>\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438<\/h3>\n<p>\u0412 STL \u0437\u0430\u0434\u0430\u0447\u0430 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 std::allocator&lt;T&gt; (\u0430 \u0442\u0430\u043a\u0436\u0435 std::pmr::polymorphic_allocator) \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0442\u0438\u043f\u043e\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 std::vector \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">template&lt;class T, class _Alloc = std::allocator&lt;T&gt;&gt; class vector;<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043a\u043b\u0430\u0441\u0441 std::allocator&lt;T&gt;.\u00a0<\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 new expression, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new (::operator new), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 new (\u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 placement new) \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0438\u043f\u0430 (\u0447\u0442\u043e \u0431\u044b \u044d\u0442\u043e \u043d\u0438 \u0431\u044b\u043b\u043e) \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0434\u0432\u0430 \u044d\u0442\u0430\u043f\u0430:<\/p>\n<ul>\n<li>\n<p>\u043c\u0435\u0442\u043e\u0434 allocator&lt;T&gt;::allocate() \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u00ab\u0441\u044b\u0440\u043e\u0433\u043e\u00bb \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u044f\u0432\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 operator new;<\/p>\n<\/li>\n<li>\n<p>\u043c\u0435\u0442\u043e\u0434 allocator&lt;T&gt;::construct(void*, _Args\u2026) \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043d\u0430 \u044d\u0442\u043e\u043c \u0443\u0447\u0430\u0441\u0442\u043a\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 placement new.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0438\u0434\u0435\u044f: \u0430 \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u0438 \u043d\u0430\u043c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434?<\/p>\n<p>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0438\u043d\u0443\u0441 \u2014 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043c\u0435\u0442\u043e\u0434\u0430 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 ObjectFactory::create(). \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">template&lt;class Base, class Key&gt; class ObjectFactory\u00a0 { \u00a0\u00a0\u00a0\u00a0\/\/ \u0432\u0441\u0435 \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u00a0\u00a0\u00a0\u00a0\/\/ ...  \u00a0\u00a0\u00a0\u00a0template&lt;class... _Args&gt; \u00a0\u00a0\u00a0\u00a0Base* create(const Key&amp; key, _Args... args) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return this-&gt;construct(std::allocator&lt;char&gt;{}, std::forward&lt;_Args&gt;(args)...); \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0template&lt;class Alloc, class\u2026 Args&gt; \u00a0\u00a0\u00a0\u00a0Base* construct(Alloc&amp; al, const Key&amp; key, Args... args) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0using CreatorType = ClassCreator&lt;_Args...&gt;; \/\/ \u0442\u0438\u043f intermezzo \u043a\u043b\u0430\u0441\u0441\u0430 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static constexpr int argc = sizeof...(_Args); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static const int argv[] = { qMetaTypeId&lt;std::decay_t&lt;_Args&gt;&gt;()... }; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (const auto&amp; c : creators_) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (c-&gt;isMatched(key, argv, argc)) \/\/ \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 \u043a intermezzo \u043a\u043b\u0430\u0441\u0441\u0443 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const CreatorType* creator = static_cast&lt;const CreatorType*&gt;(c.get()); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return creator-&gt;create(al, std::forward&lt;_Args&gt;(args)...); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return nullptr; \u00a0\u00a0\u00a0\u00a0} };<\/code><\/pre>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443 \u043c\u0435\u0442\u043e\u0434\u0430 ObjectFactory::create() \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u0437-\u0437\u0430 variardic templates \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0435 \u0432 \u0441\u0438\u043b\u0430\u0445.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c, \u043a\u0430\u043a \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 ClassCreator&lt;Args&#8230;&gt;. \u0417\u0430\u0433\u0432\u043e\u0437\u0434\u043a\u0430 \u0437\u0434\u0435\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0435. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u043d\u0430\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435, \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0430\u0434\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c. \u0422\u0430\u043a, \u0441\u0430\u043c\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 Creator&lt;_Product, _Args\u2026&gt;, \u0433\u0434\u0435 \u0442\u0438\u043f \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u0443\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d!\u00a0<\/p>\n<p>\u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u0440\u044e\u043a:\u00a0<\/p>\n<ul>\n<li>\n<p>\u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 CreatorBase \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e size_, \u0445\u0440\u0430\u043d\u044f\u0449\u0443\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0431\u0430\u0439\u0442\u0430\u0445;<\/p>\n<\/li>\n<li>\n<p>\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0435 ClassCreator&lt;_Args&#8230;&gt; \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0436\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 construct(void*,_Args&amp;&amp;\u2026);<\/p>\n<\/li>\n<li>\n<p>\u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0435 Creator&lt;_Product, <em>Args&#8230;&gt; \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 sizeof(<\/em>Product) \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 construct(void*,_Args&amp;&amp;\u2026).<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043a\u043e\u0434\u0435 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a (\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u044b \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0447\u0442\u0435\u043d\u0438\u044f):<\/p>\n<pre><code class=\"cpp\">class CreatorBase { public: \u00a0\u00a0\u00a0\u00a0\u00a0CreatorBase(const Key&amp; k, sizet n) \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0: key_(k) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, size_(n) \/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u00a0\u00a0\u00a0\u00a0\u00a0{}  \u00a0\u00a0\u00a0\u00a0virtual ~CreatorBase() = default; \u00a0\u00a0\u00a0\u00a0virtual const int* argsMeta() const { return nullptr; } \u00a0\u00a0\u00a0\u00a0virtual int argsCount() const { return 0; } \u00a0\u00a0\u00a0\u00a0const Key&amp; key() const { return key; } \u00a0\u00a0\u00a0\u00a0bool isMatched(const _Key&amp; k, const int* args, int n) const; \/\/ \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435  protected: \u00a0\u00a0\u00a0\u00a0Key key; \u00a0\u00a0\u00a0\u00a0const size_t size_; };   template&lt;class... _Args&gt; class ClassCreator : public CreatorBase { \u00a0\u00a0\u00a0\u00a0\u00a0static constexpr int kArgsCount = sizeof...(_Args); \u00a0\u00a0\u00a0\u00a0\u00a0static const int kArgsMeta[sizeof...(_Args)]; public: \u00a0\u00a0\u00a0\u00a0\u00a0ClassCreator(const Key&amp; k, sizet n) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0: CreatorBase(k, n) \/\/ \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 n \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u00a0\u00a0\u00a0\u00a0\u00a0{}  \u00a0\u00a0\u00a0\u00a0\u00a0const int* argsMeta() const override { return kArgsMeta; } \u00a0\u00a0\u00a0\u00a0\u00a0int argsCount() const override { return kArgsCount; }  \u00a0\u00a0\u00a0\u00a0\u00a0template&lt;class _Allocator&gt; \u00a0\u00a0\u00a0\u00a0\u00a0inline Base* create(const Allocator&amp; al, _Args&amp;&amp;... args) const \u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ rebind allocator \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0using allocator_type = typename std::allocator_traits&lt;_Allocator&gt;::template rebind_alloc&lt;char&gt;;  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0_Base* result = nullptr; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0allocator_type alloc_proxy(al); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0char* addr = nullptr; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0try \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u044f \u0438\/\u0438\u043b\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0addr = alloc_proxy.allocate(this-&gt;size_); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0result = construct(addr, std::forward&lt;_Args&gt;(args)...); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0catch (...) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0434\u0435\u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0alloc_proxy.deallocate(addr, this-&gt;size_); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0addr = nullptr; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return result; \u00a0\u00a0\u00a0\u00a0}  protected: \u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u00a0\u00a0\u00a0\u00a0\u00a0virtual Base* construct(void*, Args&amp;&amp;...) const = 0;\u00a0 };   template&lt;class Product, class... Args&gt; class Creator : public ClassCreator&lt;_Args...&gt; { public: \u00a0\u00a0\u00a0\u00a0Creator(const _Key&amp; k) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0: ClassCreator&lt;_Args...&gt;(k, sizeof(_Product)) \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c sizeof(_Product) \u00a0\u00a0\u00a0\u00a0{}  \u00a0\u00a0\u00a0\u00a0\/\/ \\reimp from ClassCreator&lt;...&gt; \u00a0\u00a0\u00a0\u00a0Base* construct(void* addr, Args&amp;&amp;... args) const override \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c placement new \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0432 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 addr \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return new(addr) Product(std::forward&lt;Args&gt;(args)...); \u00a0\u00a0\u00a0\u00a0} };<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u0443\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0443 ClassCreator&lt;_Args&#8230;&gt;::create(). \u0412 \u043f\u0435\u0440\u0432\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f rebind \u043a \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0443 char \u0442\u0438\u043f\u0430. \u0421\u0434\u0435\u043b\u0430\u043d\u043e \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e \u0441 \u0431\u0430\u0439\u0442\u0430\u043c\u0438. \u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0441\u043e\u0431\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0443\u0447\u0430\u0441\u0442\u043a\u0443:<\/p>\n<pre><code class=\"cpp\">try { \u00a0\u00a0\u00a0\u00a0\u00a0addr = alloc_proxy.allocate(this-&gt;size_); \u00a0\u00a0\u00a0\u00a0\u00a0result = construct(addr, std::forward&lt;_Args&gt;(args)...); } catch (...) { \u00a0\u00a0\u00a0\u00a0\u00a0alloc_proxy.deallocate(addr, this-&gt;size_); \u00a0\u00a0\u00a0\u00a0\u00a0addr = nullptr; \u00a0\u00a0\u00a0\u00a0\u00a0throw; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043d\u0435\u0442 UB, \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u0440\u043e\u0441\u0438\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f deallocate(). \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 addr \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0440\u0430\u0432\u043d\u044b\u043c nullptr, \u0430 \u0432\u044b\u0437\u043e\u0432 deallocate \u0434\u043b\u044f nullptr \u2014 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u043c\u044b \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u043c \u043f\u0430\u043c\u044f\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u044b\u043b\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0430 \u043f\u043e\u0434 \u043e\u0431\u044a\u0435\u043a\u0442, \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0437\u0431\u0435\u0436\u0438\u043c \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438.\u00a0<\/p>\n<blockquote>\n<p><strong><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/em><\/strong><em> \u0414\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432 C++20 \u0438 \u0432\u044b\u0448\u0435, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u043c std::make_obj_using_allocator().<\/em><\/p>\n<\/blockquote>\n<h3>\u0415\u0449\u0435 \u043e\u0431 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u0438 \u0442\u0438\u043f\u0430\u0445<\/h3>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u0438.<\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0430\u0448\u0435\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c draw(), \u0447\u0442\u043e\u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u044b \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0438 \u043a\u0430\u043a\u0438\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">class Shape { public: \u00a0\u00a0\u00a0\u00a0virtual ~Shape() = default; \u00a0\u00a0\u00a0\u00a0Shape(); \u00a0\u00a0\u00a0\u00a0Shape(const std::string&amp; name) : name_(name) {} \u00a0\u00a0\u00a0\u00a0virtual void draw(std::ostream&amp; out)\u00a0 const = 0; protected: \u00a0\u00a0\u00a0\u00a0std::string name_; };  class Circle : public Shape { public: \u00a0\u00a0\u00a0\u00a0Circle() : Circle(\"Circle\", 0, 0, 0.0) {} \u00a0\u00a0\u00a0\u00a0Circle(int x, int y, double r) : Circle(\"Circle\", x, y, r) {} \u00a0\u00a0\u00a0\u00a0Circle(const std::string&amp; name, int x, int y, double r)\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0: Shape(name) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, x_(x) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, y_(y) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, r_(r) \u00a0\u00a0\u00a0\u00a0{} void draw(std::ostream &amp;out) const override { \u00a0\u00a0\u00a0\u00a0out &lt;&lt; '\\'' &lt;&lt; name_&lt;&lt; \"' {\" &lt;&lt; x_ &lt;&lt; ';' &lt;&lt; y_ &lt;&lt; \"}: \"&lt;&lt; r_; } private: \u00a0\u00a0\u00a0\u00a0int x_ = 0, y_ = 0; \u00a0\u00a0\u00a0\u00a0double r_ = 0; };  class Rectangle : public Shape { public: \u00a0\u00a0\u00a0\u00a0Rectangle() : Rectangle(\"Rectangle\", 0, 0, 0, 0) {} \u00a0\u00a0\u00a0\u00a0Rectangle(int x, int y, int w, int h) : Rectangle(\"Rectangle\", x, y, w, h) {} \u00a0\u00a0\u00a0\u00a0Rectangle(const std::string&amp; name, int x, int y, int w, int h) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0: Shape(name) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, x_(x) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, y_(y) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, w_(w) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, h_(h) \u00a0\u00a0\u00a0\u00a0{} void draw(std::ostream &amp;out) const override { \u00a0\u00a0\u00a0\u00a0out &lt;&lt; '\\'' &lt;&lt; name_ &lt;&lt; \"' {\" &lt;&lt; x_ &lt;&lt; ';' &lt;&lt; y_ &lt;&lt; \"}: \" &lt;&lt; '[' &lt;&lt; w_ &lt;&lt; 'x' &lt;&lt; h_ &lt;&lt; ']'; } private: \u00a0\u00a0\u00a0int x_ = 0, y_ = 0, w_ = 0, h_ = 0; };  class Line : public Shape { public: \u00a0\u00a0\u00a0\u00a0Line() : Line(\"Line\", 0, 0, 0, 0) {} \u00a0\u00a0\u00a0\u00a0Line(int x1, int y1, int x2, int y2) : Line(\"Line\", x1, y1, x2, y2) {} \u00a0\u00a0\u00a0\u00a0Line(const std::string&amp; name, int x1, int y1, int x2, int y2) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0: Shape(name) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, x1_(x1) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, y1_(y1) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, x2_(x2) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0, y2_(y2) \u00a0\u00a0\u00a0\u00a0{} void draw(std::ostream &amp;out) const override { \u00a0\u00a0\u00a0\u00a0out &lt;&lt; '\\'' &lt;&lt; name_ &lt;&lt; \"' {\" &lt;&lt; x1_ &lt;&lt; ';' &lt;&lt; y1_ &lt;&lt; \"},\" &lt;&lt; \" {\" &lt;&lt; x2_ &lt;&lt; ';' &lt;&lt; y2_ &lt;&lt;'}'; } private: \u00a0\u00a0\u00a0\u00a0int x1_ = 0, y1_ = 0; \u00a0\u00a0\u00a0\u00a0int x2_ = 0, y2_ = 0; };<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0444\u0430\u0431\u0440\u0438\u043a\u0430:<\/p>\n<pre><code class=\"cpp\">int main() { \u00a0\u00a0\u00a0\u00a0ObjectFactory&lt;std::string, Shape&gt; factory; \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Circle&gt;(\"circle\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Circle, int, int, double&gt;(\"circle\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Circle, std::string, int, int, double&gt;(\"circle\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Rectangle&gt;(\"rect\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Rectangle, int, int, int, int&gt;(\"rect\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Rectangle, std::string, int, int, int, int&gt;(\"rect\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Line&gt;(\"line\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Line, int, int, int, int&gt;(\"line\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Line, std::string, int, int, int, int&gt;(\"line\"); \u00a0\u00a0\u00a0\u00a0std::vector&lt;std::unique_ptr&lt;Shape&gt;&gt; shapes; \u00a0\u00a0\u00a0\u00a0shapes.emplace_back(factory.create(\"circle\")); \u00a0\u00a0\u00a0\u00a0shapes.emplace_back(factory.create(\"rect\", \"MyRect\", 10, 10, 24, 24)); \u00a0\u00a0\u00a0\u00a0shapes.emplace_back(factory.create(\"line\", \"MyLine\", 0, 0, 5, 5)); \u00a0\u00a0\u00a0     for (const auto&amp; s : shapes) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (!s) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0continue; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0s-&gt;draw(std::cout); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0std::cout &lt;&lt; std::endl; \u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0return 0; }<\/code><\/pre>\n<p>\u041c\u044b \u043e\u0436\u0438\u0434\u0430\u043b\u0438 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0442\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0435, \u043e\u0434\u043d\u0430\u043a\u043e \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u2014 nullptr:<\/p>\n<pre><code class=\"cpp\">'Circle' {0;0}: 0<\/code><\/pre>\n<p><strong>\u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0437\u0434\u0435\u0441\u044c? \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f Rectagle \u0438 Line?<\/strong>\u00a0<\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u0432 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 C++. \u041a\u0430\u043a \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u043f\u0440\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u044b\u0432\u043e\u0434\u0435 \u0442\u0438\u043f\u043e\u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f <strong>\u0442\u043e\u0447\u043d\u044b\u0439<\/strong> <strong>\u0442\u0438\u043f<\/strong>. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f const char*, \u0430 \u043d\u0435 std::string. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">static const int kArgsMeta = {\u00a0 \u00a0\u00a0\u00a0\u00a0qMetaTypeId&lt;const char*&gt;(),\u00a0 \u00a0\u00a0\u00a0\u00a0qMetaTypeId&lt;int&gt;(),\u00a0 \u00a0\u00a0\u00a0\u00a0qMetaTypeId&lt;int&gt;(),\u00a0 \u00a0\u00a0\u00a0\u00a0qMetaTypeId&lt;int&gt;(),\u00a0 \u00a0\u00a0\u00a0\u00a0qMetaTypeId&lt;int&gt;() };<\/code><\/pre>\n<p>\u0425\u043e\u0442\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0431\u0443\u0434\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<pre><code class=\"cpp\">static const int kArgsMeta = {\u00a0 \u00a0\u00a0\u00a0\u00a0qMetaTypeId&lt;std::string&gt;(),\u00a0 \u00a0\u00a0\u00a0\u00a0qMetaTypeId&lt;int&gt;(),\u00a0 \u00a0\u00a0\u00a0\u00a0qMetaTypeId&lt;int&gt;(),\u00a0 \u00a0\u00a0\u00a0\u00a0qMetaTypeId&lt;int&gt;(),\u00a0 \u00a0\u00a0\u00a0\u00a0qMetaTypeId&lt;int&gt;() };<\/code><\/pre>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0443\u0436\u043d\u044b\u0439.\u00a0<\/p>\n<p><strong>\u041a\u0430\u043a \u0436\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u043d\u0430\u0447\u0430\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432?<\/strong><\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b <strong>\u044f\u0432\u043d\u043e<\/strong>. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432, \u0438 \u0432\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c:<\/p>\n<pre><code class=\"cpp\">shapes.emplace_back(factory.create(\"rect\", \"MyRect\", 10, 10, 24, 24)); shapes.emplace_back(factory.create&lt;std::string, int, int, int, int&gt;(\"rect\", \"MyRect\", 10, 10, 24, 24)); shapes.emplace_back(factory.create(\"line\", \"MyLine\", 0, 0, 5, 5)); shapes.emplace_back(factory.create&lt;std::string, int, int, int, int&gt;(\"line\", \"MyLine\", 0, 0, 5, 5));<\/code><\/pre>\n<p>\u0414\u0430, \u044d\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u043e, \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0432 \u043a\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u043d\u043e \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043c\u043d\u0435 \u043d\u0430\u0439\u0442\u0438 \u0442\u0430\u043a \u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c.<\/p>\n<p><strong>\u0410 \u0447\u0442\u043e \u0441 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u0438?<\/strong>\u00a0<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c polymorphic_allocator \u0438 monotonic_buffer_resource \u0434\u043b\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 \u0441\u0442\u0435\u043a\u0435 (\u0447\u0442\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">struct destroyer\u00a0 { \u00a0\u00a0\u00a0\u00a0template &lt;typename T&gt; \u00a0\u00a0\u00a0\u00a0constexpr void operator()(T* arg) const { std::destroy_at(arg); } };  int main() { \u00a0\u00a0\u00a0\u00a0using ShapePtr = std::unique_ptr&lt;Shape, destroyer&gt;;  \u00a0\u00a0\u00a0\u00a0\/\/ pool for Rectangle objects \u00a0\u00a0\u00a0\u00a0std::array&lt;uint8_t, sizeof(Rectangle) * 4&gt; rbuffer = { 0 }; \u00a0\u00a0\u00a0\u00a0std::pmr::monotonic_buffer_resource mbr_rects{ rbuffer.data(), rbuffer.size() }; \u00a0\u00a0\u00a0\u00a0std::pmr::polymorphic_allocator&lt;uint8_t&gt; rect_alloc{ &amp;mbr_rects };  \u00a0\u00a0\u00a0\u00a0\/\/ pool for Circle objects \u00a0\u00a0\u00a0\u00a0std::array&lt;uint8_t, sizeof(Circle) * 4&gt; cbuffer = { 0 }; \u00a0\u00a0\u00a0\u00a0std::pmr::monotonic_buffer_resource mbr_circles{ cbuffer.data(), cbuffer.size() }; \u00a0\u00a0\u00a0\u00a0std::pmr::polymorphic_allocator&lt;uint8_t&gt; circle_alloc{ &amp;mbr_circles };  \u00a0\u00a0\u00a0\u00a0\/\/ pool for Line objects \u00a0\u00a0\u00a0\u00a0std::array&lt;uint8_t, sizeof(Line) * 4&gt; lbuffer = { 0 }; \u00a0\u00a0\u00a0\u00a0std::pmr::monotonic_buffer_resource mbr_lines{ lbuffer.data(), lbuffer.size() }; \u00a0\u00a0\u00a0\u00a0std::pmr::polymorphic_allocator&lt;uint8_t&gt; line_alloc{ &amp;mbr_lines };  \u00a0\u00a0\u00a0\u00a0\/\/ Create factory and registrate types \u00a0\u00a0\u00a0\u00a0ObjectFactory&lt;String, Shape&gt; factory; \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Line&gt;(\"Line\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Line(String, int, int, int, int)&gt;(\"Line\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Rectangle()&gt;(\"Rect\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Rectangle(String, int, int, int, int)&gt;(\"Rect\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Circle&gt;(\"Circle\"); \u00a0\u00a0\u00a0\u00a0factory.registrate&lt;Circle(String, int, int, double)&gt;(\"Circle\");    \u00a0\u00a0\u00a0\u00a0\/\/ Use factory to create shapes \u00a0\u00a0\u00a0\u00a0std::vector&lt;ShapePtr&gt; shapes; \u00a0\u00a0\u00a0\u00a0shapes.emplace_back(factory.construct&lt;decltype(rect_alloc)&gt;(rect_alloc, \"Rect\")); \u00a0\u00a0\u00a0\u00a0shapes.emplace_back(factory.construct&lt;decltype(rect_alloc), String, int, int, int, int&gt;(rect_alloc, \"Rect\", \"MyRect\", 10, 10, 20, 20)); \u00a0\u00a0\u00a0     shapes.emplace_back(factory.construct&lt;decltype(circle_alloc)&gt;(circle_alloc, \"Circle\")); \u00a0\u00a0\u00a0\u00a0shapes.emplace_back(factory.construct&lt;decltype(circle_alloc), String, int, int, double&gt;(circle_alloc, \"Circle\", \"MyCircle\", 5, 5, 0.5)); \u00a0\u00a0\u00a0\u00a0shapes.emplace_back(factory.construct&lt;decltype(line_alloc)&gt;(line_alloc, \"Line\")); \u00a0\u00a0\u00a0\u00a0shapes.emplace_back(factory.construct&lt;decltype(line_alloc), String, int, int, int, int&gt;(line_alloc, \"Line\", \"MyLine\", 3, 3, 6, 6)); \u00a0\u00a0\u00a0\u00a0for (const auto&amp; s : shapes) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (!s) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0continue; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0s-&gt;draw(std::cout); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0std::cout &lt;&lt; std::endl; \u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0return 0; }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">'Rect' {0;0}: [0x0] 'MyRect' {10;10}: [20x20] 'Circle' {0;0}: 0 'MyCircle' {5;5}: 0.5 'Line' {0;0}, {0;0} 'MyLine' {3;3}, {6;6}<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 destroyer \u2014 \u043e\u043d\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 delete \u043d\u0430 \u0441\u0442\u0435\u043a\u043e\u0432\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e std::unique_ptr \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 default_deleter&lt;T&gt;, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 operator delete. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043c\u0435\u043d\u044f\u0435\u043c \u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e destroyer, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f std::destroy_at().<\/p>\n<h3>\u041f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0431\u0430\u043d\u0442\u0438\u043a\u0438<\/h3>\n<p>\u041c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438. \u0421\u0442\u043e\u0438\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Qt, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u0435\u0441\u043b\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043c\u0430\u043a\u0440\u043e\u0441\u044b Q_OBJECT \u0438\u043b\u0438 Q_GADGET, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043c\u0435\u0442\u0430\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0445. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u0442\u0438\u043f \u0442\u0430\u043a\u0443\u044e \u043c\u0435\u0442\u0430\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0442\u0435\u0445\u043d\u0438\u043a\u043e\u0439 SFINAE (Substitution-Failure-Is-Not-An-Error):<\/p>\n<pre><code class=\"cpp\">\/\/ SFINAE \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430 \u0442\u0438\u043f\u0430, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0430\u044f, \/\/ \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 T \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e staticMetaObject\u00a0 template &lt;class T&gt; class HasQtMetaObject { \u00a0\u00a0\u00a0\u00a0template&lt;class U, class = typename std::enable_if&lt;!std::is_member_pointer&lt;decltype(&amp;U::staticMetaObject)&gt;::value&gt;::type&gt; \u00a0\u00a0\u00a0\u00a0static std::true_type check(int); \u00a0\u00a0\u00a0\u00a0template &lt;class&gt; \u00a0\u00a0\u00a0\u00a0static std::false_type check(...); public: \u00a0\u00a0\u00a0\u00a0static constexpr bool value = decltype(check&lt;T&gt;(0))::value; };<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 CreatorBase \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">class CreatorBase { \u00a0\u00a0\u00a0\u00a0\/\/ ... \u00a0\u00a0\u00a0\u00a0\/\/ \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u00a0\u00a0\u00a0\u00a0virtual const QMetaObject* metaObject() const { return nullptr; } \u00a0\u00a0\u00a0\u00a0\/\/ ... };<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0432 Creator&lt;_Product, _Args&#8230;&gt; \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">template class Creator : public ClassCreator&lt;_Args...&gt; { \u00a0\u00a0\u00a0\u00a0\/\/ ... \u00a0\u00a0\u00a0\u00a0\/\/ \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u00a0\u00a0\u00a0\u00a0const QMetaObject* metaObject() const override \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if constexpr (HasQtMetaObject&lt;_Product&gt;) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return &amp;_Product::staticMetaObject; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return nullptr;\u00a0 \u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\/\/ ... };<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u0430\u043c\u043e\u0439 \u0444\u0430\u0431\u0440\u0438\u043a\u0435 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043c\u0435\u0442\u0430\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u043a\u043b\u044e\u0447\u0443. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043a\u043e\u0434 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438:<\/p>\n<pre><code class=\"cpp\">template&lt;class Key, class Base&gt; class ObjectFactory { \u00a0\u00a0\u00a0\u00a0\/\/ ... \u00a0\u00a0\u00a0\u00a0\/\/ \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u00a0\u00a0\u00a0\u00a0\/\/ ... \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0430\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 (\u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c) \u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u00a0\u00a0\u00a0\u00a0const QMetaObject* metaData(const _Key&amp; key) const noexcept \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (const auto&amp; c : creators_) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (c-&gt;key() == key) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return c-&gt;metaObject(); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return nullptr; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0\/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u00a0\u00a0\u00a0\u00a0\/\/ \u043f\u043e \u043a\u043b\u044e\u0447\u0443 key \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 _Args... \u00a0\u00a0\u00a0\u00a0template&lt;class... _Args&gt; \u00a0\u00a0\u00a0\u00a0bool contains(const _Key&amp; key) const noexcept \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static constexpr int argc = sizeof...(_Args); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static const int argv[] = { qMetaTypeId&lt;std::decay_t&lt;_Args&gt;&gt;()... }; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (const auto&amp; c : creators_) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (c-&gt;isMatched(key, argv, argc)) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return true; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return false; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0\/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439\u00a0 \u00a0\u00a0\u00a0\u00a0template&lt;class Container = QList&lt;Key&gt;&gt; \u00a0\u00a0\u00a0\u00a0_Container keys() const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0_Container result; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (const auto&amp; c : creators_) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0result.push_back(c-&gt;key());  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0std::sort(result.begin(), result.end()); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0result.erase(std::unique(result.begin(), result.end()), result.end()); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return result; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0\/\/ \u041f\u043e\u0434\u0441\u0447\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0430 key \u00a0\u00a0\u00a0\u00a0int count(const _Key&amp; key) const noexcept \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int n = 0; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (const auto&amp; c : creators_) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0n += (c-&gt;key() == key); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return n; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0\/\/ \u041e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0432\u0441\u0435\u0445 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u0432 \u00a0\u00a0\u00a0\u00a0int size() const noexcept \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return creators_.size(); \u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\/\/ ... };<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f std::function&lt;&gt;, \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u00ab\u0431\u0430\u043d\u0442\u0438\u043a\u00bb. \u041c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u0430 \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f:<\/p>\n<pre><code class=\"cpp\">factory.registrate&lt;Circle, std::string, int, int, double&gt;(\"circle\");<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0433\u0434\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f, \u0430 \u0433\u0434\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430. \u0411\u044b\u043b\u043e \u0431\u044b \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u00ab\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c\u00bb \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">factory.registrate&lt;Circle(std::string, int, int, double)&gt;(\"circle\");<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0442\u0430\u043a\u0430\u044f \u043d\u043e\u0442\u0430\u0446\u0438\u044f \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043a\u043e\u0434 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u0443\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043b\u044f \u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">template&lt;class Product, class... Args&gt; struct ClassRegisterer { \u00a0\u00a0\u00a0\u00a0static void registrate(ObjectFactory&amp; factory, const _Key&amp; key) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert (std::is_base_of_v&lt;_Base, Product&gt;, \"Product must be derived from _base type\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static constexpr int argc = sizeof...(_Args); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static const int argv[] = { qMetaTypeId&lt;_Args&gt;()... }; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (const auto&amp; c : std::as_const(factory.creators_)) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (c-&gt;isMatched(key, argv, argc)) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0factory.creators_.push_back(std::make_unique&lt;Creator&lt;_Product, _Args...&gt;&gt;(key)); \u00a0\u00a0\u00a0\u00a0} };  template&lt;class Product, class... Args&gt; struct ClassRegisterer&lt;_Product(_Args...)&gt; \u00a0\u00a0\u00a0\u00a0: public ClassRegisterer&lt;_Product, _Args...&gt; {};<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u0430\u0444\u0443\u043d\u043a\u0446\u0438\u0438 std::enable_if_t&lt;&gt; \u0438 std::is_function_v&lt;&gt; \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438:<\/p>\n<pre><code class=\"cpp\">template&lt;class Key, class Base&gt; class ObjectFactory { \u00a0\u00a0\u00a0\u00a0\/\/ \u00a0\u00a0\u00a0\/\/ ...  \u00a0\u00a0\u00a0\u00a0template&lt;class Product, class... Args&gt; \u00a0\u00a0\u00a0\u00a0inline typename std::enable_if_t&lt;!std::is_function_v&lt;_Product&gt;, void&gt; registrate(const _Key&amp; key) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ClassRegisterer&lt;_Product, _Args...&gt;::registrate(*this, key); \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0template&lt;class _Fn&gt; \u00a0\u00a0\u00a0\u00a0inline typename std::enable_if_t&lt;std::is_function_v&lt;_Fn&gt;, void&gt; registrate(const _Key&amp; key) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ClassRegisterer&lt;_Fn&gt;::registrate(*this, key); \u00a0\u00a0\u00a0\u00a0} };<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0440\u0430\u0437\u0443 <strong>\u043e\u0431\u0435\u0438\u0445 \u043d\u043e\u0442\u0430\u0446\u0438\u0439<\/strong>:<\/p>\n<pre><code class=\"cpp\">factory.registrate&lt;Circle, std::string, int, int, double&gt;(\"circle\");  factory.registrate&lt;Circle(std::string, int, int, double)&gt;(\"circle\");<\/code><\/pre>\n<h3>\u0422\u0430\u043a\u0438\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0438<\/h3>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0435\u0449\u0435 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0441\u0430\u043c\u0438\u0445 \u0444\u0430\u0431\u0440\u0438\u043a \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0441 \u0430\u0432\u0442\u043e\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0432 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0438.\u00a0<\/p>\n<p>\u0424\u0430\u0431\u0440\u0438\u043a\u0430 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0444\u0430\u0431\u0440\u0438\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 (\u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435) \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 (\u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430) \u0438\u0437 \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0436\u0435 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0420\u0435\u0448\u0435\u043d\u0438\u0435, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435, \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0443\u0431\u0440\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u0444\u0430\u0431\u0440\u0438\u043a\u0438:<\/p>\n<pre><code class=\"cpp\">template&lt;class Key, class Base&gt; class PrototypeFactory { \u00a0\u00a0\u00a0\u00a0using FactoryType = ObjectFactory&lt;_Key, _Base&gt;; \u00a0\u00a0\u00a0\u00a0using PrototypeMap = std::unordered_map&lt;std::string, std::unique_ptr&lt;Shape&gt;&gt;;  \u00a0\u00a0\u00a0\u00a0template&lt;class... _Args&gt; \u00a0\u00a0\u00a0\u00a0Shape* create(const std::string&amp; key, _Args... args) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (!impl_.contains(key, args...)) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return nullptr; \/\/ \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435 key\/args... \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto [it, inserted] = prototypes_.emplace(key, {}); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (inserted)\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Base* p = impl.create&lt;_Args...&gt;(key, std::forward&lt;_Args&gt;(args)...); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0it-&gt;second.reset(p); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return it-&gt;second; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0435\u0441\u043b\u0438 Shape \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ return it-&gt;second-&gt;clone();\u00a0 \u00a0\u00a0\u00a0\u00a0}  private: \u00a0\u00a0\u00a0\u00a0FactoryType impl_; \u00a0\u00a0\u00a0\u00a0PrototypeMap prototypes_; };<\/code><\/pre>\n<p>\u0424\u0430\u0431\u0440\u0438\u043a\u0430 \u0441 \u0430\u0432\u0442\u043e\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0444\u0430\u0431\u0440\u0438\u043a\u0438, \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044b\u0439 \u0432 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d. \u0417\u0434\u0435\u0441\u044c \u043d\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0441 \u043d\u0443\u043b\u044f. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u043e\u0439 \u0444\u0430\u0431\u0440\u0438\u043a\u0438:<\/p>\n<pre><code class=\"cpp\">using ShapeFactory = ObjectFactory&lt;std::string, Shape&gt;;  \/\/ \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d \u041c\u0435\u0439\u0435\u0440\u0441\u0430\u00a0 ShapeFactory&amp; shapeFactory() { \u00a0\u00a0\u00a0\u00a0static ShapeFactory globalInstance; \u00a0\u00a0\u00a0\u00a0return globalInstance; }  \/\/ \u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 template&lt;class T, class... _Args&gt; struct ShapeRegisterer\u00a0 { \u00a0\u00a0\u00a0\u00a0explicit ShapeRegisterer(const std::string&amp; k) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0shapeFactory().registrate&lt;T(_Args...)&gt;(k); \u00a0\u00a0\u00a0\u00a0} };  \/\/ \u041c\u0430\u043a\u0440\u043e\u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 #define REGISTRATE_SHAPE_CLASS(_Class) \\ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static const ShapeRegisterer&lt;_Class&gt; __##_Class##Registerer{ #_Class };<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u043a\u0440\u043e\u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438:\u00a0<\/p>\n<ul>\n<li>\n<p>\u043c\u0430\u043a\u0440\u043e\u0441 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b ShapeRegisterer, \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0442\u0438\u043f\u043e\u043c _Class;<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 __##_Class##Registerer \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u044e \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439;<\/p>\n<\/li>\n<li>\n<p>#_Class \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 _Class.\u00a0<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0449\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u00ab\u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u043c\u00bb \u043c\u0430\u043a\u0440\u043e\u0441, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Circle:<\/p>\n<pre><code class=\"cpp\">static const ShapeRegisterer&lt;Circle&gt; __CircleRegisterer{ \u201cCircle\u201d };<\/code><\/pre>\n<p>\u0424\u0438\u0448\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443 C++, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 <em>\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435<\/em> \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 <strong>\u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 main-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/strong>. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0449\u0435 \u0434\u043e \u0432\u0445\u043e\u0434\u0430 \u0432 main() \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 ShapeRegisterer&lt;Circle&gt;, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 (\u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0435\u0449\u0435 \u043d\u0435 \u0431\u044b\u043b\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430) \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0442\u0438\u043f\u0430.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u043c, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u043c __VA_ARGS__, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043b\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432, \u043a\u0430\u043a variardic template argument pack \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u043c\u044f, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0442\u0435\u043f\u0435\u0440\u044c \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 _Id:<\/p>\n<pre><code class=\"cpp\">\/\/ \u041c\u0430\u043a\u0440\u043e\u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438  #define REGISTRATE_SHAPE_CLASS(_Class, _Id, ...) \\  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static const ShapeRegisterer&lt;_Class, __VA_ARGS__&gt; __##_Class##Registerer##_Id { #_Class };<\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u0442\u0438\u043f\u0430 Shape \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">\/\/ MyShape.h class MyShape : public Shape { public: \u00a0\u00a0\u00a0\u00a0MyShape(); \u00a0\u00a0\u00a0\u00a0MyShape(const std::string&amp; name, int i); \u00a0\u00a0\u00a0\u00a0void draw(std::ostream&amp; out) const override; private: \u00a0\u00a0\u00a0\u00a0int i_; };  \/\/ MyShape.cpp #include \"MyShape.h\"  MyShape::MyShape() : Shape(\"myshape\") {}  MyShape::MyShape(const std::string&amp; name, int i) : Shape(name), i_(i) {}  void MyShape::draw(std::ostream&amp; out) const { out &lt;&lt; \"MyShape: \" &lt;&lt; i_; }  \/\/ \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e MyShape \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435 REGISTRATE_SHAPE_CLASS(MyShape, 0)\u00a0 REGISTRATE_SHAPE_CLASS(MyShape, 1, std::string, int)\u00a0<\/code><\/pre>\n<p>\u0414\u043b\u044f <em>\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 <\/em>\u043a\u043e\u043c\u043f\u043e\u043d\u0443\u0435\u043c\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0442\u0430\u043a\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <em>\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e <\/em>\u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u0433\u0440\u0430\u043d\u0438\u0446 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f MyShape \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0443\u0435\u043c\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u0441\u0430\u043c\u043e\u0439 \u0444\u0430\u0431\u0440\u0438\u043a\u0438, \u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u043c REGISTER_SHAPE_CLASS(), \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u0435\u043d\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u043a\u0430\u043a \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0438 \u043a\u043b\u0430\u0441\u0441 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435.\u00a0<\/p>\n<blockquote>\n<p><strong><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: <\/em><\/strong><em>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442, \u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u0438\u0435\u043c\u043e\u0432 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/em><\/p>\n<\/blockquote>\n<h3>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 Boost<\/h3>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u044f \u043d\u0435 \u043f\u0435\u0440\u0432\u044b\u0439, \u043a\u0442\u043e \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u0412\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442 \u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Boost \u0438 \u0435\u0435 \u043c\u043e\u0434\u0443\u043b\u044f\u0445 Boost.Fuctional\/Factory \u0438 <a href=\"http:\/\/Boost.In\" rel=\"noopener noreferrer nofollow\">Boost.In<\/a>-Place Factory.<\/p>\n<p>\u0421\u0440\u0430\u0437\u0443 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0430\u0445.\u00a0<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d <em>\u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439<\/em>, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u043e\u0438\u0441\u043a\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u044f\u0432\u043d\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 \u043f\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430.<\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Boost.Fuctional\/Factory \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d <em>\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0430\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0430<\/em>: \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0435 \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u0443\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0437\u0434\u0435\u0441\u044c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u2014 \u0434\u043b\u044f \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, std::map).<\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"http:\/\/Boost.In\" rel=\"noopener noreferrer nofollow\">Boost.In<\/a>-Place Factory \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0431\u0435\u0437 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f tag dispatching.<\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u0446\u0435\u043b\u044f\u0445 \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u0445 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c.<\/p>\n<p>\u041c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\"><strong>\u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0439<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>ObjectFactory<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>Boost.Factory<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><a href=\"http:\/\/Boost.In\" rel=\"noopener noreferrer nofollow\"><strong>Boost.In<\/strong><\/a><strong>-Place Factory<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<\/td>\n<td>\n<p align=\"left\">Compile-time + Run-time \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 ID \u0442\u0438\u043f\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">Run-time \u0447\u0435\u0440\u0435\u0437 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">Compile-time \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438\u00a0<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u042f\u0432\u043d\u0430\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u0430\u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u0440\u044f\u043c\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Type Erasure<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 Intermezzo \u043a\u043b\u0430\u0441\u0441\u044b<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f boost::function<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u043e\u0447\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\"><strong>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>ObjectFactory<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>Boost<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Variardic Arguments<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0430 (\u0421++11 fold expressions)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0430 (\u0447\u0435\u0440\u0435\u0437 bind)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Argument Forwarding<\/p>\n<\/td>\n<td>\n<p align=\"left\">Perfect Forwarding<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f boost::bind<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Dependency Injection<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0420\u0443\u0447\u043d\u0430\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0442\u0438\u043f\u043e\u0432<\/p>\n<\/td>\n<td>\n<p align=\"left\">Boost.DI<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Code Bloating<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u0440\u0435\u0434\u043d\u044f\u044f (\u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412\u044b\u0441\u043e\u043a\u0430\u044f (\u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 + \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043c\u0435\u0442\u0430\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438\/Qt<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\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 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0448\u043b\u0438 \u043f\u0443\u0442\u044c \u043e\u0442 \u0441\u0430\u043c\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0445. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u0443\u043c\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441\u044b \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439, \u0443\u0434\u0435\u043b\u044f\u044f \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/p>\n<ul>\n<li>\n<p>\u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u043c\u0443 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043f\u0430\u043c\u044f\u0442\u044c\u044e;<\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0438 \u043c\u0435\u0442\u0430\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u043a\u0440\u043e\u0441\u0441-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0441\u0442\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0431\u0430\u043b\u0430\u043d\u0441\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>\u0432 \u0432\u044b\u0441\u043e\u043a\u043e\u0447\u0430\u0441\u0442\u043e\u0442\u043d\u043e\u043c \u0442\u0440\u0435\u0439\u0434\u0438\u043d\u0433\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u0434\u043b\u044f \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c;<\/p>\n<\/li>\n<li>\n<p>\u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u0434\u0432\u0438\u0436\u043a\u0430\u0445;<\/p>\n<\/li>\n<li>\n<p>\u043f\u043b\u0430\u0433\u0438\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0432 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0435\u0442 \u00ab\u0441\u0435\u0440\u0435\u0431\u0440\u044f\u043d\u043e\u0439 \u043f\u0443\u043b\u0438\u00bb, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0432\u043e \u0432\u0441\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u0438 \u0447\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439, \u0441\u0430\u043c\u044b\u0439 \u0441\u043b\u043e\u0436\u043d\u044b\u0439, \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0442\u0435\u043c, \u0447\u0442\u043e \u0440\u0435\u0448\u0438\u0442 \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u0442\u043e\u0438\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445.\u00a0<\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u0437\u0434\u0435\u0441\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u044a\u0435\u043c\u0430 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0438\u043c\u0435\u0442\u044c \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u043c \u0447\u0430\u0449\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <em>\u043e\u0434\u043d\u043e\u0444\u0430\u0437\u043d\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/em>. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043b\u043e\u0436\u0438\u0442\u0441\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0440\u044f\u0434 \u043b\u0438 \u0443\u0434\u0430\u0441\u0442\u0441\u044f.\u00a0<\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, <em>\u0434\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/em> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0434\u0438\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0444\u0430\u0431\u0440\u0438\u043a\u0435 \u0441 variardic templates \u0432 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438. \u041e\u0442\u043c\u0435\u0447\u0443 \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e \u043f\u0440\u0438 \u0434\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0436\u0435\u0441\u0442\u043a\u0438\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0445 \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u0435\u0435.\u00a0<\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0435\u0441\u043b\u0438 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043c\u043d\u043e\u0433\u043e \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d, \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0442\u0440\u0435\u0442\u044c\u0438\u0445 \u0441\u0442\u043e\u0440\u043e\u043d, \u043a\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u0442\u043e \u0432\u044b\u0431\u043e\u0440\u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u2014 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u0438\u0435\u043c\u044b.<\/p>\n<p>\u0426\u0435\u043b\u044c\u044e \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c production-ready \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0441\u043a\u043e\u0440\u0435\u0435 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u044f\u0437\u044b\u043a\u0430 C++ \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439. \u041d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u0435\u043c\u044b \u0442\u043e\u0447\u043d\u043e \u0441\u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0435\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u0443 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445. <\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/932358\/\"> https:\/\/habr.com\/ru\/articles\/932358\/<\/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<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041c\u0438\u0445\u0430\u0438\u043b \u041f\u043e\u043b\u0443\u043a\u0430\u0440\u043e\u0432, \u044f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 Desktop-\u0432\u0435\u0440\u0441\u0438\u0438 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0441\u0443\u043f\u0435\u0440\u0430\u043f\u043f\u0430 \u0434\u043b\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b <a href=\"https:\/\/biz.mail.ru\/teams\/?utm_source=habr&amp;utm_medium=refferal&amp;utm_campaign=fabrica_dlya_std\" rel=\"noopener noreferrer nofollow\">VK Teams<\/a>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438, \u0433\u0434\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Factory Method \u0438\u043b\u0438 AbstractFactory. \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u044f \u043d\u0435\u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u043b\u043e\u0432\u0438\u043b \u0441\u0435\u0431\u044f \u043d\u0430 \u043c\u044b\u0441\u043b\u0438, \u0447\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u043f\u0438\u0448\u0443 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0439 \u043a\u043e\u0434 \u0442\u0430\u043a\u0438\u0445 \u0444\u0430\u0431\u0440\u0438\u043a, \u0438 \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u0441\u0430\u043c\u043e\u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439.\u00a0<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c DRY (Don\u2019t Repeat Yourself), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u00ab\u0444\u0438\u0448\u043a\u0438\u00bb \u043d\u043e\u0432\u044b\u0445 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432 \u0421++.\u00a0<\/p>\n<blockquote>\n<p><strong><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: <\/em><\/strong><em>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 <\/em><a href=\"https:\/\/github.com\/progzdeveloper\/HabrQtDemos\/tree\/main\/ObjectFactory\" rel=\"noopener noreferrer nofollow\"><em>\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 GitHub<\/em><\/a><em>. \u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 C++17 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Qt, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0441\u0442\u0435\u043a.<\/em><\/p>\n<\/blockquote>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0424\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0430\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c\u0438 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u0440\u0438\u0447\u0438\u043d \u044d\u0442\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0432 C++ \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0432 \u044f\u0437\u044b\u043a \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u00ab\u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e\u00bb \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432: \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0435\u0441\u0442\u044c, \u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u0436\u0435 (\u0438\u043b\u0438 \u043f\u043e\u0445\u043e\u0436\u0435\u0433\u043e) \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u2014 \u043d\u0435\u0442. \u0421\u0432\u044f\u0437\u0430\u043d\u043e \u044d\u0442\u043e \u0441\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432 \u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u0430\u043c\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430, \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0434\u0430\u043b\u0435\u043a\u043e \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.\u00a0<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0438\u0437 \u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430: \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0432 \u0442\u043e\u0439 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0438\u0448\u0435\u0442\u0435 \u043a\u043e\u0434 \u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u0442\u0438\u043f\u043e\u0432, \u0442\u043e \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0434\u043e\u043b\u0435\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u044b\u043b \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u044b\u043c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043f\u0435\u0440\u0432\u0430 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">class Shape { public: \u00a0\u00a0\u00a0\u00a0virtual ~Shape() = default; \u00a0\u00a0\u00a0\u00a0\/\/ ... };  class Circle : public Shape { ... }; class Rectangle : public Shape { ... }; class Line : public Shape { ... };<\/code><\/pre>\n<h3>Dummy Factory<\/h3>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u0438. \u041e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">class ShapeFactory { \u00a0\u00a0\u00a0\u00a0class Creator \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual ~Creator() = default; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual Shape* create() const = 0; \u00a0\u00a0\u00a0\u00a0};  \u00a0\u00a0\u00a0\u00a0template&lt;class _Shape&gt; \u00a0\u00a0\u00a0\u00a0class ShapeCreator : public Creator \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual Shape* create() const override \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return new _Shape; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0}; \u00a0\u00a0\u00a0\u00a0using CreatorPointer = std::unique_ptr&lt;Creator&gt;;  public: \u00a0\u00a0\u00a0\u00a0\u00a0template&lt;class _Shape&gt; \u00a0\u00a0\u00a0\u00a0\u00a0void registrate(const std::string&amp; key) \u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert(std::is_base_of_v&lt;Shape, Shape&gt;, \"Shape must be derived from Shape\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto[it, inserted] = creators_.emplace(key, {}); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (inserted) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0it-&gt;second.reset(new Creator&lt;_Shape&gt;); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Shape* createShape(const std::string&amp; key) const \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto it = creators_.find(key); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return it != creators_.end() ? it-&gt;second-&gt;create() : nullptr; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}  private: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0std::unordered_map&lt;std::string, CreatorPointer&gt; creators_; };<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c: \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u043d\u0435\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Creator \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0431\u0435\u0437 \u043e\u0441\u043e\u0431\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0442\u0430\u043a \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0443:<\/p>\n<pre><code class=\"cpp\">ShapeFactory factory; factory.registrate&lt;Circle&gt;(\"cirlce\"); factory.registrate&lt;Rectangle&gt;(\"rectanle\"); factory.registrate&lt;Line&gt;(\"line\"); factory.registrate&lt;MyShape&gt;(\"myshape\"); \/\/ \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0444\u0438\u0433\u0443\u0440\u044b std::vector&lt;std::unique_ptr&lt;Shape&gt;&gt; shapes; shapes.emplace_back(factory.create(\"circle\")); shapes.emplace_back(factory.create(\"rectangle\")); \/\/ ... \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435<\/code><\/pre>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e: \u043d\u0443\u0436\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f, \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u043e\u0434 \u0438 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0435\u0433\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::function&lt;&gt; \u0432\u043c\u0435\u0441\u0442\u043e Creator \u0438 ShapeCreator&lt;_Shape&gt;. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u043c\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>\u043e\u0442 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u2014 std::function&lt;&gt; \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c pointer-semantic \u043d\u0430 value-semantic, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u0441\u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e;<\/p>\n<\/li>\n<li>\n<p>\u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0432 heap \u2014 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 std::function&lt;&gt; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Small-Value-Optimization;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u2014 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u043e\u0442\u043e\u043a \u0438 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0435\u043d.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0440\u043e\u043c\u0435 \u043f\u0440\u043e\u0447\u0435\u0433\u043e, \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">class ShapeFactory { public: \u00a0\u00a0\u00a0\u00a0using Creator = std::function&lt;Shape*()&gt;;  \u00a0\u00a0\u00a0\u00a0template&lt;class _Shape&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const std::string&amp; key, const Creator&amp; c) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert(std::is_base_of_v&lt;Shape, Shape&gt;, \u201cShape must be derived from Shape\u201d); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = c; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0template&lt;class _Shape&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const std::string&amp; key) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert(std::is_base_of_v&lt;Shape, Shape&gt;, \u201cShape must be derived from Shape\u201d); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = []() -&gt; Shape* { return new _Shape; }; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0Shape* createShape(const std::string&amp; key) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto it = creators_.find(key); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return it != creators_.end() ? (it-&gt;second)() : nullptr; \u00a0\u00a0\u00a0\u00a0}  private: \u00a0\u00a0\u00a0\u00a0\u00a0std::unordered_map&lt;std::string, Creator&gt; creators_; };<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e:<\/p>\n<ul>\n<li>\n<p>\u0422\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0435\u0433\u043e \u0441\u043c\u0435\u043d\u0438\u0442\u044c, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u044f\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0438\u0445 \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u0447\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0422\u0438\u043f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0432\u0441\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u0441 \u043d\u0443\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438 \u043a Generic Factory<\/h3>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0442\u044c \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0412\u044b\u0434\u0435\u043b\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e:<\/p>\n<ul>\n<li>\n<p>\u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u0432\u043d\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0442\u0438\u043f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u0432\u043d\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0442\u0438\u043f\u044b \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u0432\u043d\u0435;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0443\u0436\u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 RTTI;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Qt \u0438 Qt Meta-Object System.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u0443\u0434\u0435\u043c \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u0443\u043d\u043a\u0442\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<h4>\u0422\u0438\u043f\u044b \u043a\u043b\u044e\u0447\u0430 \u0438 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u043f\u0443\u043d\u043a\u0442\u0430 \u043f\u0440\u043e\u0441\u0442\u044b \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u043c:<\/p>\n<pre><code class=\"cpp\">template&lt; \u00a0\u00a0\u00a0\u00a0class _Key, \/\/ \u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u00a0\u00a0\u00a0\u00a0class _Base \/\/ \u0442\u0438\u043f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 &gt; class ObjectFactory { public: \u00a0\u00a0\u00a0\u00a0using Creator = std::function&lt;_Base*()&gt;;  \u00a0\u00a0\u00a0\u00a0template&lt;class _Product&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const _Key&amp; key, const Creator&amp; c) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert(std::is_base_of_v&lt;_Base, Product&gt;, \"Product must be derived from _Base\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = c; \u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0     template&lt;class _Product&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const _Key&amp; key) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert(std::is_base_of_v&lt;_Base, Product&gt;, \"Product must be derived from _Base\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = []() -&gt; Base* { return new Product; }; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0_Base* createShape(const Key&amp; key) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto it = creators_.find(key); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return it != creators_.end() ? (it-&gt;second)() : nullptr; \u00a0\u00a0\u00a0\u00a0}  private: \u00a0\u00a0\u00a0\u00a0std::unordered_map&lt;_Key, Creator&gt; creators_; };<\/code><\/pre>\n<p>\u0421\u0430\u043c \u043a\u043e\u0434 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u0440\u043f\u0435\u043b \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Shape, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435:<\/p>\n<pre><code class=\"cpp\">using ShapeFactory = ObjectFactory&lt;QString, Shape&gt;;<\/code><\/pre>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0443\u043d\u043a\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c, \u043d\u043e \u0442\u0443\u0442-\u0442\u043e \u0438 \u0442\u0430\u0438\u0442\u0441\u044f \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430.\u00a0<\/p>\n<h4>\u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0438\u0445 \u0442\u0438\u043f\u044b<\/h4>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430: \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c variadic template \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0448\u0430\u0431\u043b\u043e\u043d \u043a\u043b\u0430\u0441\u0441\u0430 ObjectFactory:<\/p>\n<pre><code class=\"cpp\">template&lt; \u00a0\u00a0\u00a0\u00a0class _Key, \/\/ \u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 \u00a0\u00a0\u00a0\u00a0class _Base, \/\/ \u0442\u0438\u043f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u00a0\u00a0\u00a0\u00a0class... _Args \/\/ \u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 &gt; class ObjectFactory { public: \u00a0\u00a0\u00a0\u00a0using Creator = std::function&lt;_Base*(_Args&amp;&amp;...)&gt;;  \u00a0\u00a0\u00a0\u00a0template&lt;class _Product&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const _Key&amp; key, const Creator&amp; c) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert (std::is_base_of_v&lt;_Base, Product&gt;, \"Product must inherited from _Base\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = c; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0template&lt;class _Product&gt; \u00a0\u00a0\u00a0\u00a0void registrate(const _Key&amp; key) \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static_assert (std::is_base_of_v&lt;_Base, Product&gt;, \"Product must inherited from _Base\"); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0creators_[key] = [](_Args&amp;&amp;... args) { return new Product(std::forward&lt;Args&gt;(args)...); }; \u00a0\u00a0\u00a0\u00a0}  \u00a0\u00a0\u00a0\u00a0Base* create(const Key&amp; key, _Args&amp;&amp;... args) const \u00a0\u00a0\u00a0\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0auto it = creators_.find(key); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return it != creators_.cend() ? (it-&gt;second)(std::forward&lt;_Args&gt;(args)...) : nullptr; \u00a0\u00a0\u00a0\u00a0}  private: \u00a0\u00a0\u00a0\u00a0std::unordered_map&lt;_Key, Creator&gt; creators_; };<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0445\u043e\u0434 \u0432\u043f\u043e\u043b\u043d\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u2014 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u041d\u043e \u0437\u0430\u0433\u0432\u043e\u0437\u0434\u043a\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u0443 \u0432\u0441\u0435\u0445 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430. \u041a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430, \u0442\u0430\u043a \u0431\u044b\u0432\u0430\u0435\u0442 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u2014 \u0421++ \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c, \u0441\u043a\u0430\u0436\u0435\u043c, \u043d\u0430 QPushButton:<\/p>\n<pre><code class=\"cpp\">explicit QPushButton(QWidget *parent = nullptr); explicit QPushButton(const QString &amp;text, QWidget *parent = nullptr); QPushButton(const QIcon&amp; icon, const QString &amp;text, QWidget *parent = nullptr);<\/code><\/pre>\n<p>\u0421 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u0432\u044b\u0439\u0434\u0435\u0442.<\/p>\n<h3>\u041f\u0440\u044b\u0436\u043e\u043a \u0432 \u043a\u0440\u043e\u043b\u0438\u0447\u044c\u044e \u043d\u043e\u0440\u0443<\/h3>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0432\u0441\u0435 \u043c\u043e\u0438 \u043c\u044b\u0442\u0430\u0440\u0441\u0442\u0432\u0430 \u043f\u043e \u043f\u043e\u0438\u0441\u043a\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043d\u043e \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e: \u043a\u0440\u043e\u043b\u0438\u0447\u044c\u044f \u043d\u043e\u0440\u0430 \u0433\u043b\u0443\u0431\u043e\u043a\u0430.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043f\u043e\u0447\u0442\u0438 \u0441\u0440\u0430\u0437\u0443: \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441\u0442\u0430\u043b\u043e \u043a\u0440\u0430\u0442\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435. \u041c\u0430\u043b\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u044f\u0441\u043d\u043e, \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043e\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0438 \u0434\u043b\u044f \u0432\u0430\u0440\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u0430\u043a \u0435\u0449\u0435 \u0438 \u043d\u0435 \u044f\u0441\u043d\u043e, \u043a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.\u00a0<\/p>\n<p>\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441-\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u043a\u043b\u044e\u0447?\u00a0<\/p>\n<p>\u0423\u0445\u0438\u0449\u0440\u0435\u043d\u0438\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u043d\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043c\u0435\u0442\u0430\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0442\u0438\u043f\u0430\u0445. \u0412\u0441\u0435 \u0438\u0434\u0435\u0438 \u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0432\u043e\u043a\u0440\u0443\u0433 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u043a-\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0440\u0442\u0435\u0436 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.\u00a0<\/p>\n<p>\u041a\u0430\u043a \u0432\u0430\u0440\u0438\u0430\u043d\u0442: \u0441\u043e\u0437\u0434\u0430\u0442\u044c std::tuple&lt;_Args&#8230;&gt; \u0438 \u0432\u0437\u044f\u0442\u044c \u043e\u0442 \u043d\u0435\u0433\u043e typeid. \u041d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b RTTI,<\/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-469053","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/469053","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=469053"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/469053\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=469053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=469053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=469053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}