{"id":466573,"date":"2025-07-09T15:00:40","date_gmt":"2025-07-09T15:00:40","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=466573"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=466573","title":{"rendered":"<span>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430 \u0431\u0435\u0437 virtual \u043d\u0430 C++: \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b, \u0442\u0440\u0435\u0439\u0442\u044b \u0438 Ref<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>  \u042f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0421++ \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0442\u043e\u0440\u0433\u043e\u0432\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c. \u0418\u0434\u0435\u0439\u043d\u043e, \u043e\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0430\u0440\u043a\u0435\u0442\u2011\u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e\u0440\u0433\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e, \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043c\u0430\u0440\u043a\u0435\u0442\u2011\u043c\u0435\u0439\u043a\u0435\u0440\u0430 \u0438\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441.<\/p>\n<p>  \u041c\u0435\u0441\u044f\u0446 \u043d\u0430\u0437\u0430\u0434 \u044f \u0432\u044b\u043b\u043e\u0436\u0438\u043b \u043f\u0435\u0440\u0432\u0443\u044e \u043c\u0438\u043d\u043e\u0440\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0444\u0438\u0434\u0431\u044d\u043a \u043d\u0430 \u043f\u0440\u043e\u0444\u0438\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u0445. \u041e\u0442\u043a\u043b\u0438\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0436\u0438\u0432\u044b\u043c, \u043f\u0440\u043e\u0435\u043a\u0442 \u043e\u0431\u0440\u043e\u0441 \u043d\u043e\u0432\u044b\u043c\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0438 \u0431\u043b\u0438\u0436\u0435 \u043f\u043e\u0434\u043e\u0448\u0451\u043b \u043a \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u0438\u043d\u0434\u0443\u0441\u0442\u0440\u0438\u0438.<\/p>\n<p>  \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u044b\u043b: \u00ab\u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e virtual?\u00bb.<br \/>  \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u041e\u041e\u2011\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u0440\u0430\u0434\u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0439. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u044b) \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u0434\u0430\u0451\u0442 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>  \u041d\u043e \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u044f \u0446\u0435\u043d\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u044d\u0442\u043e \u0443\u0445\u0443\u0434\u0448\u0435\u043d\u0438\u0435 \u043a\u0435\u0448\u2011\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0440\u043e\u0441\u0442 \u043f\u0440\u043e\u043c\u0430\u0445\u043e\u0432 \u043a\u0435\u0448\u0430 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432. \u041c\u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u043b\u0430 \u0431\u044b \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438. \u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e\u043c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0441\u0442\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u0440\u044b \u043d\u0430 \u0434\u0435\u043c\u043e\u2011\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u043e\u043c \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u0430\u044f \u0438\u0434\u0435\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0448\u043b\u0430 \u043c\u043d\u0435 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 &#8212; \u043c\u043e\u043d\u043e\u0442\u0438\u043f\u044b \u0441 \u0440\u0443\u0447\u043d\u044b\u043c\u0438 vtable. \u042d\u0442\u043e \u043d\u0435 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u0451\u043c, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0432 folly::poly, LLVM \u0438 Unreal Engine. \u0414\u043e C++20 \u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0431\u044b\u043b \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043c\u0438\u043d\u0443\u0441, \u0441\u043b\u0430\u0431\u0430\u044f \u0442\u0438\u043f\u043e\u0432\u0430\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u044f \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b.<\/p>\n<p>  \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0432 \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0440\u0438\u0430\u0434\u043e\u0439 \u00ab\u043a\u043e\u043d\u0446\u0435\u043f\u0442, \u0442\u0440\u0435\u0439\u0442, \u0445\u0435\u043d\u0434\u043b\u00bb. \u041a\u043e\u043d\u0446\u0435\u043f\u0442 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u0440\u0435\u0439\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e vtable, \u0430 \u0445\u0435\u043d\u0434\u043b, \u043a\u0430\u043a \u043c\u043e\u043d\u043e\u0442\u0438\u043f, \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438. \u041d\u043e \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442?<\/p>\n<h4>\u041f\u0435\u0440\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u00ab\u043f\u0440\u043e\u0442\u0443\u0445\u0430\u044e\u0449\u0438\u0445\u00bb view<\/h4>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f \u043f\u043e\u0434\u0435\u043b\u0438\u043b \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0432\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438: \u043b\u0438\u0431\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043b\u0435\u0436\u0438\u0442 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c \u0431\u0443\u0444\u0435\u0440\u0435 \u0445\u0435\u043d\u0434\u043b\u0430, \u0435\u0441\u043b\u0438 \u0432\u043b\u0435\u0437\u0430\u0435\u0442, \u043b\u0438\u0431\u043e \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u0445\u0435\u043d\u0434\u043b \u0441\u043d\u0430\u0440\u0443\u0436\u0438. \u0412\u0441\u0451 \u0448\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0432 view &#8212; \u043d\u0435\u0432\u043b\u0430\u0434\u0435\u044e\u0449\u0435\u043c \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0435 \u043d\u0430 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442. \u042f \u0445\u043e\u0442\u0435\u043b \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0441 \u0445\u0435\u043d\u0434\u043b\u043e\u043c \u043a\u0430\u043a \u0441 value\u2011\u0442\u0438\u043f\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438, \u043d\u043e \u043f\u0440\u0438 inline\u2011\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f view \u0442\u0435\u0440\u044f\u043b \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0448\u0438\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c view \u043d\u0430 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043d\u0438\u0445 \u0440\u044b\u043d\u043e\u0447\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043d\u043e \u043f\u0440\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u043e\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c.<\/p>\n<h4>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f 2: fat pointer + \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440<\/h4>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 \u0438\u0442\u043e\u0433\u0435 \u044f \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043e\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0445\u0435\u043d\u0434\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <code>using Allocator = ...,<\/code> \u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0434\u0451\u0442 \u0447\u0435\u0440\u0435\u0437 \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 Allocator \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0421\u0435\u0439\u0447\u0430\u0441 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0444\u0440\u0438\u2011\u043b\u0438\u0441\u0442. \u0421\u0430\u043c \u0445\u0435\u043d\u0434\u043b \u044f \u043d\u0430\u0437\u0432\u0430\u043b <code>Ref<\/code>: \u043f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e fat-pointer &#8212; \u043f\u0430\u0440\u0430 void* + \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 vtable.<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Ref<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">template &lt;typename Trait&gt; class Ref {  public:   using VTable = typename Trait::VTable;    template &lt;typename Impl&gt;   static Ref from(Impl* ptr) {     static constexpr VTable vt = Trait::template makeVTable&lt;Impl&gt;();     return Ref{ptr, &amp;vt};   }    template &lt;typename T&gt; T&amp; get() const { return *static_cast&lt;T*&gt;(_ptr); }   const VTable* vtable() const noexcept { return _vtable; }   void* raw() const noexcept { return _ptr; }   private:   Ref(void* p, const VTable* v) : _ptr(p), _vtable(v) {}   void* _ptr{};   const VTable* _vtable{}; };<\/code><\/pre>\n<\/div>\n<\/details>\n<h4>\u041a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0440\u0435\u0439\u0442 \u0438 vtable<\/h4>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 Flox <code>VTable<\/code> \u044d\u0442\u043e constexpr-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 &#8212; \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u0414\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0445\u0435\u043b\u043f\u0435\u0440 <code>meta::wrap&lt;&amp;T::method&gt;()<\/code> \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u0438\u0434\u0430 <code>R (*)(void* self, Args...)<\/code>. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u0430\u0440\u0440\u0438\u0440\u0443\u0435\u0442 this: \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <code>static_cast&lt;T*&gt;(self)-&gt;method(args...)<\/code>, \u0447\u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 C-style \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0443\u0436\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u0442\u0440\u0438\u0430\u0434\u044b, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u0438\u043f \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">template &lt;typename T&gt; concept Subsystem = requires(T t) {  { t.start() } -&gt; std::same_as&lt;void&gt;;  { t.stop() } -&gt; std::same_as&lt;void&gt;; }; struct SubsystemTrait {   struct VTable {     void (*start)(void*);     void (*stop)(void*);   };    template &lt;typename T&gt;     requires concepts::Subsystem&lt;T&gt;   static constexpr VTable makeVTable() {     return { meta::wrap&lt;&amp;T::start&gt;(), meta::wrap&lt;&amp;T::stop&gt;() };   } };  class SubsystemRef : public RefBase&lt;SubsystemRef, SubsystemTrait&gt; {  public:   using RefBase::RefBase;   void start() const { _vtable-&gt;start(_ptr); }   void stop()  const { _vtable-&gt;stop(_ptr);  } };<\/code><\/pre>\n<\/div>\n<\/details>\n<h4>\u0410\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u044f \u0442\u0440\u0435\u0439\u0442\u043e\u0432: \u043a\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043c\u0430\u043b\u043e<\/h4>\n<p>\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446. \u0421\u043e\u0441\u0442\u0430\u0432\u043d\u0430\u044f vtable \u0445\u0440\u0430\u043d\u0438\u0442 \u0430\u0434\u0440\u0435\u0441 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044f \u043e\u0434\u0438\u043d \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>Ref&lt;Trait&gt;<\/code> \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043f\u0430\u0440\u0430 <code>{void* object, const VTable* table}<\/code>, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0447\u0435\u0440\u0435\u0437 <code>SomeTrait::VTable::as&lt;OtherTrait&gt;()<\/code>, \u0447\u0442\u043e\u0431\u044b \u0442\u0430 \u0436\u0435 \u0441\u0430\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0430\u043a <code>Ref&lt;OtherTrait&gt;<\/code> \u0431\u0435\u0437 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439. \u0422\u0430\u043a\u043e\u0435 \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0440\u0435\u0439\u0442\u0430\u0445 \u0438 \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u044f\u043c\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0443.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439, \u043a\u0430\u043a <code>MarketDataSubscriberTrait<\/code> \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 <code>SubscriberTrait<\/code> \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0434\u043b\u044f \u0442\u0438\u043a\u043e\u0432\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u043e\u043b\u044e <code>subscriber<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 <code>vtable<\/code> \u0441\u0441\u044b\u043b\u043a\u0430 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u0438\u0436\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u0434\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f MarketDataSubscriberTrait<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">template &lt;typename T&gt; concept MarketDataSubscriber =    Subscriber&lt;T&gt; &amp;&amp;    requires(T t, const BookUpdateEvent&amp; b, const TradeEvent&amp; tr, const CandleEvent&amp; c) {      { t.onBookUpdate(b) } -&gt; std::same_as&lt;void&gt;;      { t.onTrade(tr) } -&gt; std::same_as&lt;void&gt;;      { t.onCandle(c) } -&gt; std::same_as&lt;void&gt;;    };  struct MarketDataSubscriberTrait {   struct VTable {     const SubscriberTrait::VTable* subscriber;     void (*onBookUpdate)(void*, const BookUpdateEvent&amp;);     void (*onTrade)(void*, const TradeEvent&amp;);     void (*onCandle)(void*, const CandleEvent&amp;);      template &lt;typename Trait&gt;     const typename Trait::VTable* as() const {       if constexpr (std::is_same_v&lt;Trait, SubscriberTrait&gt;)         return subscriber;       static_assert(sizeof(Trait) == 0, \"Trait not supported\");     }   };    template &lt;typename T&gt;     requires concepts::MarketDataSubscriber&lt;T&gt;   static constexpr VTable makeVTable() {     static constexpr auto sub = SubscriberTrait::makeVTable&lt;T&gt;();     return {         &amp;sub,         meta::wrap&lt;&amp;T::onBookUpdate&gt;(),         meta::wrap&lt;&amp;T::onTrade&gt;(),         meta::wrap&lt;&amp;T::onCandle&gt;()     };   } };  class MarketDataSubscriberRef : public RefBase&lt;MarketDataSubscriberRef, MarketDataSubscriberTrait&gt; {  public:   using RefBase::RefBase;   SubscriberId   id() const { return _vtable-&gt;subscriber-&gt;id(_ptr); }   SubscriberMode mode() const { return _vtable-&gt;subscriber-&gt;mode(_ptr); }   void onTrade(const TradeEvent&amp; ev) const { _vtable-&gt;onTrade(_ptr, ev); }   void onBookUpdate(const BookUpdateEvent&amp; e) const { _vtable-&gt;onBookUpdate(_ptr, e); }   void onCandle(const CandleEvent&amp; ev) const { _vtable-&gt;onCandle(_ptr, ev); } };<\/code><\/pre>\n<\/div>\n<\/details>\n<h4>\u0426\u0438\u0444\u0440\u044b, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u0441\u0451 \u0432\u0435\u043b\u043e\u0441\u044c<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043e\u0432\u0441\u0435\u043c \u043a\u043e\u0440\u043e\u0442\u043a\u043e: +19% \u043a \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0430 \u0434\u0435\u043c\u043e \u0437\u0430 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f (30 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0440\u043e\u0433\u043e\u043d).<br \/>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0443\u0441\u0440\u0435\u0434\u043d\u0451\u043d\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u0435\u0441\u044f\u0442\u0438 \u043f\u0440\u043e\u0433\u043e\u043d\u043e\u0432 \u0442\u043e\u0433\u043e \u0436\u0435 \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0441\u0442\u0430\u0440\u044b\u0439 virtual-\u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u043e\u0442\u0438\u0432 \u043d\u043e\u0432\u043e\u0433\u043e Ref).<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"center\"><strong>\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\"><strong>\u0421\u0442\u0430\u0440\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u041d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u0394<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u0394, %<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">2760<strong> <\/strong>\u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">800 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u22121960 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221271<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">onTrade \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">960 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">330 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u2212630 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221265<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">end\u2011to\u2011end \u0437\u0430 \u0442\u0438\u043a<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">4600 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">2450 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u22122150 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221247<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">140k<\/p>\n<\/td>\n<td>\n<p align=\"center\">167k<\/p>\n<\/td>\n<td>\n<p align=\"center\">+27k<\/p>\n<\/td>\n<td>\n<p align=\"center\">+19<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">L1\u2011D miss ratio<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">3.69%<\/p>\n<\/td>\n<td>\n<p align=\"center\">2.72\u202f%<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u22120.97 \u043f.\u202f\u043f.<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221226<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">instr \/ msg<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">360k<\/p>\n<\/td>\n<td>\n<p align=\"center\">280k<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221280k<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221222<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0435\u0441\u0442 (\u043c\u0438\u043a\u0440\u043e\u0431\u0435\u043d\u0447, \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 gist \u0432\u043d\u0438\u0437\u0443) \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 17.09\u202f\u0446\u0438\u043a\u043b\u043e\u0432 \u043f\u0440\u043e\u0442\u0438\u0432 14.82\u202f\u0446\u0438\u043a\u043b\u043e\u0432 \u043d\u0430 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432, \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 13% \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438.<\/p>\n<h4>\u042d\u043f\u0438\u043b\u043e\u0433<\/h4>\n<p>\u041a\u043e\u043d\u0446\u0435\u043f\u0442\u044b \u043f\u043b\u044e\u0441 \u0440\u0443\u0447\u043d\u044b\u0435 vtable \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430 \u0431\u0435\u0437 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0435\u0439\u0442\u044b \u0434\u0430\u0451\u0442 compile\u2011time \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 dyn Trait \u0432 Rust.<\/p>\n<p>\u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0433\u043b\u0443\u0431\u0436\u0435, \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0438\u0436\u0435.<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/FLOX-Foundation\/flox\/commit\/5e6c2c6b1ac44bd54c7d808c828e3574e9b3a3f4\" rel=\"noopener noreferrer nofollow\">\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f virtual\u2011\u0432\u0435\u0442\u043a\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/FLOX-Foundation\/flox\/commit\/1815fa3512f8b40f8ad9d922e788a404cb9a09f6\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u043a\u0443\u0449\u0430\u044f trait\u2011\u043c\u043e\u0434\u0435\u043b\u044c<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/gist.github.com\/eeiaao\/6d8f8644aafa9d4d491d54238e22d646\" rel=\"noopener noreferrer nofollow\">\u043c\u0438\u043a\u0440\u043e\u0442\u0435\u0441\u0442<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0430\u043c Flox \u0436\u0438\u0432\u0451\u0442 <a href=\"https:\/\/github.com\/FLOX-Foundation\/flox\" rel=\"noopener noreferrer nofollow\">\u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0430\u0434\u0440\u0435\u0441\u0443<\/a>. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0439\u0442\u0435\u0441\u044c, \u0441\u043e\u0431\u0438\u0440\u0430\u0439\u0442\u0435 \u0441\u0432\u043e\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u043e\u043f\u044b\u0442\u043e\u043c.<\/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\/926282\/\"> https:\/\/habr.com\/ru\/articles\/926282\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>  \u042f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0421++ \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0442\u043e\u0440\u0433\u043e\u0432\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c. \u0418\u0434\u0435\u0439\u043d\u043e, \u043e\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0430\u0440\u043a\u0435\u0442\u2011\u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e\u0440\u0433\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e, \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043c\u0430\u0440\u043a\u0435\u0442\u2011\u043c\u0435\u0439\u043a\u0435\u0440\u0430 \u0438\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441.<\/p>\n<p>  \u041c\u0435\u0441\u044f\u0446 \u043d\u0430\u0437\u0430\u0434 \u044f \u0432\u044b\u043b\u043e\u0436\u0438\u043b \u043f\u0435\u0440\u0432\u0443\u044e \u043c\u0438\u043d\u043e\u0440\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0444\u0438\u0434\u0431\u044d\u043a \u043d\u0430 \u043f\u0440\u043e\u0444\u0438\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u0445. \u041e\u0442\u043a\u043b\u0438\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0436\u0438\u0432\u044b\u043c, \u043f\u0440\u043e\u0435\u043a\u0442 \u043e\u0431\u0440\u043e\u0441 \u043d\u043e\u0432\u044b\u043c\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0438 \u0431\u043b\u0438\u0436\u0435 \u043f\u043e\u0434\u043e\u0448\u0451\u043b \u043a \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u0438\u043d\u0434\u0443\u0441\u0442\u0440\u0438\u0438.<\/p>\n<p>  \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u044b\u043b: \u00ab\u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e virtual?\u00bb.<br \/>  \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u041e\u041e\u2011\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u0440\u0430\u0434\u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0439. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u044b) \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u0434\u0430\u0451\u0442 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>  \u041d\u043e \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u044f \u0446\u0435\u043d\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u044d\u0442\u043e \u0443\u0445\u0443\u0434\u0448\u0435\u043d\u0438\u0435 \u043a\u0435\u0448\u2011\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0440\u043e\u0441\u0442 \u043f\u0440\u043e\u043c\u0430\u0445\u043e\u0432 \u043a\u0435\u0448\u0430 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432. \u041c\u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u043b\u0430 \u0431\u044b \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438. \u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e\u043c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0441\u0442\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u0440\u044b \u043d\u0430 \u0434\u0435\u043c\u043e\u2011\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u043e\u043c \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u0430\u044f \u0438\u0434\u0435\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0448\u043b\u0430 \u043c\u043d\u0435 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 &#8212; \u043c\u043e\u043d\u043e\u0442\u0438\u043f\u044b \u0441 \u0440\u0443\u0447\u043d\u044b\u043c\u0438 vtable. \u042d\u0442\u043e \u043d\u0435 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u0451\u043c, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0432 folly::poly, LLVM \u0438 Unreal Engine. \u0414\u043e C++20 \u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0431\u044b\u043b \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043c\u0438\u043d\u0443\u0441, \u0441\u043b\u0430\u0431\u0430\u044f \u0442\u0438\u043f\u043e\u0432\u0430\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u044f \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b.<\/p>\n<p>  \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0432 \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0440\u0438\u0430\u0434\u043e\u0439 \u00ab\u043a\u043e\u043d\u0446\u0435\u043f\u0442, \u0442\u0440\u0435\u0439\u0442, \u0445\u0435\u043d\u0434\u043b\u00bb. \u041a\u043e\u043d\u0446\u0435\u043f\u0442 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u0440\u0435\u0439\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e vtable, \u0430 \u0445\u0435\u043d\u0434\u043b, \u043a\u0430\u043a \u043c\u043e\u043d\u043e\u0442\u0438\u043f, \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438. \u041d\u043e \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442?<\/p>\n<h4>\u041f\u0435\u0440\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u00ab\u043f\u0440\u043e\u0442\u0443\u0445\u0430\u044e\u0449\u0438\u0445\u00bb view<\/h4>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f \u043f\u043e\u0434\u0435\u043b\u0438\u043b \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0432\u0435 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438: \u043b\u0438\u0431\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043b\u0435\u0436\u0438\u0442 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c \u0431\u0443\u0444\u0435\u0440\u0435 \u0445\u0435\u043d\u0434\u043b\u0430, \u0435\u0441\u043b\u0438 \u0432\u043b\u0435\u0437\u0430\u0435\u0442, \u043b\u0438\u0431\u043e \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u0445\u0435\u043d\u0434\u043b \u0441\u043d\u0430\u0440\u0443\u0436\u0438. \u0412\u0441\u0451 \u0448\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0432 view &#8212; \u043d\u0435\u0432\u043b\u0430\u0434\u0435\u044e\u0449\u0435\u043c \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0435 \u043d\u0430 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442. \u042f \u0445\u043e\u0442\u0435\u043b \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0441 \u0445\u0435\u043d\u0434\u043b\u043e\u043c \u043a\u0430\u043a \u0441 value\u2011\u0442\u0438\u043f\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438, \u043d\u043e \u043f\u0440\u0438 inline\u2011\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f view \u0442\u0435\u0440\u044f\u043b \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0448\u0438\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c view \u043d\u0430 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043d\u0438\u0445 \u0440\u044b\u043d\u043e\u0447\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043d\u043e \u043f\u0440\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u043e\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c.<\/p>\n<h4>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f 2: fat pointer + \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440<\/h4>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 \u0438\u0442\u043e\u0433\u0435 \u044f \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043e\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0445\u0435\u043d\u0434\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <code>using Allocator = ...,<\/code> \u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0434\u0451\u0442 \u0447\u0435\u0440\u0435\u0437 \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 Allocator \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0421\u0435\u0439\u0447\u0430\u0441 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0444\u0440\u0438\u2011\u043b\u0438\u0441\u0442. \u0421\u0430\u043c \u0445\u0435\u043d\u0434\u043b \u044f \u043d\u0430\u0437\u0432\u0430\u043b <code>Ref<\/code>: \u043f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e fat-pointer &#8212; \u043f\u0430\u0440\u0430 void* + \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 vtable.<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Ref<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">template &lt;typename Trait&gt; class Ref {  public:   using VTable = typename Trait::VTable;    template &lt;typename Impl&gt;   static Ref from(Impl* ptr) {     static constexpr VTable vt = Trait::template makeVTable&lt;Impl&gt;();     return Ref{ptr, &amp;vt};   }    template &lt;typename T&gt; T&amp; get() const { return *static_cast&lt;T*&gt;(_ptr); }   const VTable* vtable() const noexcept { return _vtable; }   void* raw() const noexcept { return _ptr; }   private:   Ref(void* p, const VTable* v) : _ptr(p), _vtable(v) {}   void* _ptr{};   const VTable* _vtable{}; };<\/code><\/pre>\n<\/div>\n<\/details>\n<h4>\u041a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0440\u0435\u0439\u0442 \u0438 vtable<\/h4>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 Flox <code>VTable<\/code> \u044d\u0442\u043e constexpr-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 &#8212; \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u0414\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0445\u0435\u043b\u043f\u0435\u0440 <code>meta::wrap&lt;&amp;T::method&gt;()<\/code> \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u0438\u0434\u0430 <code>R (*)(void* self, Args...)<\/code>. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u0430\u0440\u0440\u0438\u0440\u0443\u0435\u0442 this: \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <code>static_cast&lt;T*&gt;(self)-&gt;method(args...)<\/code>, \u0447\u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 C-style \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0443\u0436\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u0442\u0440\u0438\u0430\u0434\u044b, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u0438\u043f \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">template &lt;typename T&gt; concept Subsystem = requires(T t) {  { t.start() } -&gt; std::same_as&lt;void&gt;;  { t.stop() } -&gt; std::same_as&lt;void&gt;; }; struct SubsystemTrait {   struct VTable {     void (*start)(void*);     void (*stop)(void*);   };    template &lt;typename T&gt;     requires concepts::Subsystem&lt;T&gt;   static constexpr VTable makeVTable() {     return { meta::wrap&lt;&amp;T::start&gt;(), meta::wrap&lt;&amp;T::stop&gt;() };   } };  class SubsystemRef : public RefBase&lt;SubsystemRef, SubsystemTrait&gt; {  public:   using RefBase::RefBase;   void start() const { _vtable-&gt;start(_ptr); }   void stop()  const { _vtable-&gt;stop(_ptr);  } };<\/code><\/pre>\n<\/div>\n<\/details>\n<h4>\u0410\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u044f \u0442\u0440\u0435\u0439\u0442\u043e\u0432: \u043a\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043c\u0430\u043b\u043e<\/h4>\n<p>\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446. \u0421\u043e\u0441\u0442\u0430\u0432\u043d\u0430\u044f vtable \u0445\u0440\u0430\u043d\u0438\u0442 \u0430\u0434\u0440\u0435\u0441 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044f \u043e\u0434\u0438\u043d \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>Ref&lt;Trait&gt;<\/code> \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043f\u0430\u0440\u0430 <code>{void* object, const VTable* table}<\/code>, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0447\u0435\u0440\u0435\u0437 <code>SomeTrait::VTable::as&lt;OtherTrait&gt;()<\/code>, \u0447\u0442\u043e\u0431\u044b \u0442\u0430 \u0436\u0435 \u0441\u0430\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0430\u043a <code>Ref&lt;OtherTrait&gt;<\/code> \u0431\u0435\u0437 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439. \u0422\u0430\u043a\u043e\u0435 \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0440\u0435\u0439\u0442\u0430\u0445 \u0438 \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u044f\u043c\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0443.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439, \u043a\u0430\u043a <code>MarketDataSubscriberTrait<\/code> \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 <code>SubscriberTrait<\/code> \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0434\u043b\u044f \u0442\u0438\u043a\u043e\u0432\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u043e\u043b\u044e <code>subscriber<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 <code>vtable<\/code> \u0441\u0441\u044b\u043b\u043a\u0430 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u0438\u0436\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u0434\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f MarketDataSubscriberTrait<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">template &lt;typename T&gt; concept MarketDataSubscriber =    Subscriber&lt;T&gt; &amp;&amp;    requires(T t, const BookUpdateEvent&amp; b, const TradeEvent&amp; tr, const CandleEvent&amp; c) {      { t.onBookUpdate(b) } -&gt; std::same_as&lt;void&gt;;      { t.onTrade(tr) } -&gt; std::same_as&lt;void&gt;;      { t.onCandle(c) } -&gt; std::same_as&lt;void&gt;;    };  struct MarketDataSubscriberTrait {   struct VTable {     const SubscriberTrait::VTable* subscriber;     void (*onBookUpdate)(void*, const BookUpdateEvent&amp;);     void (*onTrade)(void*, const TradeEvent&amp;);     void (*onCandle)(void*, const CandleEvent&amp;);      template &lt;typename Trait&gt;     const typename Trait::VTable* as() const {       if constexpr (std::is_same_v&lt;Trait, SubscriberTrait&gt;)         return subscriber;       static_assert(sizeof(Trait) == 0, \"Trait not supported\");     }   };    template &lt;typename T&gt;     requires concepts::MarketDataSubscriber&lt;T&gt;   static constexpr VTable makeVTable() {     static constexpr auto sub = SubscriberTrait::makeVTable&lt;T&gt;();     return {         &amp;sub,         meta::wrap&lt;&amp;T::onBookUpdate&gt;(),         meta::wrap&lt;&amp;T::onTrade&gt;(),         meta::wrap&lt;&amp;T::onCandle&gt;()     };   } };  class MarketDataSubscriberRef : public RefBase&lt;MarketDataSubscriberRef, MarketDataSubscriberTrait&gt; {  public:   using RefBase::RefBase;   SubscriberId   id() const { return _vtable-&gt;subscriber-&gt;id(_ptr); }   SubscriberMode mode() const { return _vtable-&gt;subscriber-&gt;mode(_ptr); }   void onTrade(const TradeEvent&amp; ev) const { _vtable-&gt;onTrade(_ptr, ev); }   void onBookUpdate(const BookUpdateEvent&amp; e) const { _vtable-&gt;onBookUpdate(_ptr, e); }   void onCandle(const CandleEvent&amp; ev) const { _vtable-&gt;onCandle(_ptr, ev); } };<\/code><\/pre>\n<\/div>\n<\/details>\n<h4>\u0426\u0438\u0444\u0440\u044b, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u0441\u0451 \u0432\u0435\u043b\u043e\u0441\u044c<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043e\u0432\u0441\u0435\u043c \u043a\u043e\u0440\u043e\u0442\u043a\u043e: +19% \u043a \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0430 \u0434\u0435\u043c\u043e \u0437\u0430 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f (30 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0440\u043e\u0433\u043e\u043d).<br \/>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0443\u0441\u0440\u0435\u0434\u043d\u0451\u043d\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u0435\u0441\u044f\u0442\u0438 \u043f\u0440\u043e\u0433\u043e\u043d\u043e\u0432 \u0442\u043e\u0433\u043e \u0436\u0435 \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0441\u0442\u0430\u0440\u044b\u0439 virtual-\u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u043e\u0442\u0438\u0432 \u043d\u043e\u0432\u043e\u0433\u043e Ref).<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"center\"><strong>\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\"><strong>\u0421\u0442\u0430\u0440\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u041d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u0394<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u0394, %<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">2760<strong> <\/strong>\u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">800 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u22121960 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221271<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">onTrade \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">960 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">330 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u2212630 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221265<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">end\u2011to\u2011end \u0437\u0430 \u0442\u0438\u043a<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">4600 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">2450 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u22122150 \u043d\u0441<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221247<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">140k<\/p>\n<\/td>\n<td>\n<p align=\"center\">167k<\/p>\n<\/td>\n<td>\n<p align=\"center\">+27k<\/p>\n<\/td>\n<td>\n<p align=\"center\">+19<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">L1\u2011D miss ratio<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">3.69%<\/p>\n<\/td>\n<td>\n<p align=\"center\">2.72\u202f%<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u22120.97 \u043f.\u202f\u043f.<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221226<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">instr \/ msg<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"center\">360k<\/p>\n<\/td>\n<td>\n<p align=\"center\">280k<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221280k<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u221222<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0435\u0441\u0442 (\u043c\u0438\u043a\u0440\u043e\u0431\u0435\u043d\u0447, \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 gist \u0432\u043d\u0438\u0437\u0443) \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 17.09\u202f\u0446\u0438\u043a\u043b\u043e\u0432 \u043f\u0440\u043e\u0442\u0438\u0432 14.82\u202f\u0446\u0438\u043a\u043b\u043e\u0432 \u043d\u0430 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432, \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 13% \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438.<\/p>\n<h4>\u042d\u043f\u0438\u043b\u043e\u0433<\/h4>\n<p>\u041a\u043e\u043d\u0446\u0435\u043f\u0442\u044b \u043f\u043b\u044e\u0441 \u0440\u0443\u0447\u043d\u044b\u0435 vtable \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430 \u0431\u0435\u0437 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0435\u0439\u0442\u044b \u0434\u0430\u0451\u0442 compile\u2011time \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 dyn Trait \u0432 Rust.<\/p>\n<p>\u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0433\u043b\u0443\u0431\u0436\u0435, \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0438\u0436\u0435.<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/FLOX-Foundation\/flox\/commit\/5e6c2c6b1ac44bd54c7d808c828e3574e9b3a3f4\" rel=\"noopener noreferrer nofollow\">\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f virtual\u2011\u0432\u0435\u0442\u043a\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/FLOX-Foundation\/flox\/commit\/1815fa3512f8b40f8ad9d922e788a404cb9a09f6\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u043a\u0443\u0449\u0430\u044f trait\u2011\u043c\u043e\u0434\u0435\u043b\u044c<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/gist.github.com\/eeiaao\/6d8f8644aafa9d4d491d54238e22d646\" rel=\"noopener noreferrer nofollow\">\u043c\u0438\u043a\u0440\u043e\u0442\u0435\u0441\u0442<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0430\u043c Flox \u0436\u0438\u0432\u0451\u0442 <a href=\"https:\/\/github.com\/FLOX-Foundation\/flox\" rel=\"noopener noreferrer nofollow\">\u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0430\u0434\u0440\u0435\u0441\u0443<\/a>. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0439\u0442\u0435\u0441\u044c, \u0441\u043e\u0431\u0438\u0440\u0430\u0439\u0442\u0435 \u0441\u0432\u043e\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u043e\u043f\u044b\u0442\u043e\u043c.<\/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\/926282\/\"> https:\/\/habr.com\/ru\/articles\/926282\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-466573","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466573","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=466573"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466573\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=466573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=466573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=466573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}