{"id":884,"date":"2011-04-25T05:00:59","date_gmt":"2011-04-25T10:00:59","guid":{"rendered":"http:\/\/www.jaimerios.com\/?p=884"},"modified":"2011-04-25T05:00:59","modified_gmt":"2011-04-25T10:00:59","slug":"setting-a-boost-shared_ptr-to-null","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=884","title":{"rendered":"Setting a boost shared_ptr to NULL"},"content":{"rendered":"<p>If you need to set a boost shared_ptr to NULL, then you can do it like this:<\/p>\n<pre lang=\"CPP\">\nboost::shared_ptr<OohClass>();\n<\/pre>\n<p>So, if you have a function that returns a boost shared_ptr and you want to pass NULL to represent either an error state or a not-found state, you can do this:<\/p>\n<pre lang=\"CPP\">\n#include <map>\ntypedef boost::shared_ptr<OohClass> OohClassPtr;\ntypedef std::map< const char*, OohClassPtr > OohClassMap;\n\nOohClassPtr FindMyClass( const char* key, OohClassMap& ocmRef )\n{\n\tOohClassPtr ptr;\n\tOohClassMap::iterator itr = ocmRef.find(key);\n\tif (itr != ocmRef.end())\n\t\tptr = itr->second;\n\telse\n\t\tptr = boost::shared_ptr<OohClass>();\n\treturn ptr;\n}\n<\/pre>\n<p>Handy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need to set a boost shared_ptr to NULL, then you can do it like this: boost::shared_ptr(); So, if you have a function that returns a boost shared_ptr and you want to pass NULL to represent either an error state or a not-found state, you can do this: #include typedef boost::shared_ptr OohClassPtr; typedef std::map< ... <a title=\"Setting a boost shared_ptr to NULL\" class=\"read-more\" href=\"https:\/\/jaimerios.com\/?p=884\" aria-label=\"Read more about Setting a boost shared_ptr to NULL\">Read 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":[3],"tags":[87,100,143,402],"class_list":["post-884","post","type-post","status-publish","format-standard","hentry","category-coding","tag-boost","tag-c","tag-cpp","tag-shared_ptr"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=884"}],"version-history":[{"count":0,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/884\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}