{"id":1191,"date":"2024-01-19T17:34:17","date_gmt":"2024-01-19T09:34:17","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=1191"},"modified":"2024-01-19T17:34:41","modified_gmt":"2024-01-19T09:34:41","slug":"stdreference_wrapper","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=1191","title":{"rendered":"std::reference_wrapper"},"content":{"rendered":"<p>std::reference_wrapper<br \/>\nC++ Utilities library Function objects std::reference_wrapper<br \/>\nDefined in header <functional><\/p>\n<pre><code class=\"language-cpp\">template&lt; class T &gt;\nclass reference_wrapper;<\/code><\/pre>\n<p>(since C++11)<br \/>\nstd::reference_wrapper is a class template that wraps a reference in a copyable, assignable object.<\/p>\n<p>Specifically, std::reference_wrapper is a CopyConstructible and CopyAssignable wrapper around a reference to object or reference to function of type T. Instances of std::reference_wrapper are objects (they can be copied or stored in containers) but they are implicitly convertible to T&amp;, so that they can be used as arguments with the functions that take the underlying type by reference.<\/p>\n<p>If the stored reference is Callable, std::reference_wrapper is callable with the same arguments.<\/p>\n<p>Helper functions std::ref and std::cref are often used to generate std::reference_wrapper objects.<\/p>\n<p>std::reference_wrapper is used to pass objects by reference to std::bind, the constructor of std::thread, or the helper functions std::make_pair and std::make_tuple. It can also be used as a mechanism to store references inside standard containers (like std::vector) that cannot normally hold references.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>std::reference_wrapper C++ Utilities library Function objects std::reference_wrapper Defined in header template&lt; class T &gt; class reference_wrapper; (since C++11) std::reference_wrapper is a class template that wraps a reference in a copyable, assignable object. Specifically, std::reference_wrapper is a CopyConstructible and CopyAssignable wrapper around a reference to object or reference to function of type T. Instances of std::reference_wrapper [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=1191\" title=\"Permanent Link to: std::reference_wrapper\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1191","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1191"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1191"}],"version-history":[{"count":2,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1191\/revisions"}],"predecessor-version":[{"id":1193,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1191\/revisions\/1193"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}