{"id":12,"date":"2003-05-08T20:48:34","date_gmt":"2003-05-08T19:48:34","guid":{"rendered":"http:\/\/www.nobugs.org\/blog\/archives\/2003\/05\/08\/stl-transform-meets-constructors\/"},"modified":"2003-05-08T20:48:34","modified_gmt":"2003-05-08T19:48:34","slug":"stl-transform-meets-constructors","status":"publish","type":"post","link":"https:\/\/www.nobugs.org\/blog\/archives\/2003\/05\/08\/stl-transform-meets-constructors\/","title":{"rendered":"STL transform() meets constructors"},"content":{"rendered":"<p>Using the STL transform() function you can apply &#8220;function like things&#8221; to a collection to make a new collection.  That means anything which can be called by sticking brackets after it, so functions are fine and function objects are fine.<\/p>\n<p>But not all &#8220;function like things&#8221; work.  What happens if you have a collection of ints, and you want to transform them into a collection of Foo&#8217;s, where the constructor for class &#8220;Foo&#8221; takes a single integer argument.<\/p>\n<p>Well, you can&#8217;t just pass &#8220;Foo&#8221; to transform() because that&#8217;s a type, not a value.  You can&#8217;t pass Foo::Foo either,  It doesn&#8217;t work.<\/p>\n<p>You <i>can<\/i> create a static method, say Create(int i), which just builds a Foo object and returns it.  That works.  But it&#8217;s incredibly inelegant.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using the STL transform() function you can apply &#8220;function like things&#8221; to a collection to make a new collection. That means anything which can be called by sticking brackets after it, so functions are fine and function objects are fine. But not all &#8220;function like things&#8221; work. What happens if you have a collection of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":0,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}