{"id":172,"date":"2014-07-15T19:50:53","date_gmt":"2014-07-16T01:50:53","guid":{"rendered":"http:\/\/jacobncalvert.com\/?p=172"},"modified":"2018-02-10T15:59:32","modified_gmt":"2018-02-10T21:59:32","slug":"c-2014-auto-return-deduction-and-more","status":"publish","type":"post","link":"https:\/\/jacobncalvert.com\/blog-archive\/2014\/07\/15\/c-2014-auto-return-deduction-and-more\/","title":{"rendered":"C++ 2014: auto return deduction and more!"},"content":{"rendered":"<p>The new C++ standard-in-the-making codenamed C++1y, has some great new features.<\/p>\n<p>The most standout addition in my opinion is the &#8216;return type deduction&#8217; feature which allows functions to use &#8216;auto&#8217; return types that will be deduced at runtime. There are a few limits on this functionality however. Recursion can only happen if there is at least one return statement that can be evaluated to a non-auto type. For example:<\/p>\n<pre class=\"prettyprint\">\/\/ this factorial works\r\nauto factorial(int i)\r\n{\r\n    if(i == 0 || i == 1)\r\n    {\r\n        return 1;\r\n    }\r\n    else\r\n    {\r\n        return i * factorial(i-1);\r\n    }\r\n}\r\n\/\/ this one will not\r\nauto factorial2(int i)\r\n{\r\n    if(i &gt; 1)\r\n    {\r\n        return i * factorial(i-1);\r\n    }\r\n    else\r\n    {\r\n        return 1;\r\n    }\r\n}\r\n\r\n\r\n<\/pre>\n<p>This feature is very neat and somewhat &#8216;Pythonic.&#8217; In C++11 the\u00a0<i>lambda<\/i>\u00a0feature already allows this auto typing but in C++14 it will be available to all functions.<br \/>\nAnother notable addition to C++ in the latest upcoming release is the introduction of binary literals. With this, you can explicitly specify binary numbers with syntax like:<b><br \/>\n<\/b><\/p>\n<pre class=\"prettyprint\">int nine = 0B1001;\r\n<\/pre>\n<p><b><br \/>\n<\/b>There are many, many more language features being added in C++14; too many to note in detail. Check out more at\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/C%2B%2B14#Function_return_type_deduction\">the Wikipedia article<\/a>\u00a0for C++1y or at\u00a0<a href=\"https:\/\/isocpp.org\/std\/status\">the standards status page for C++<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The new C++ standard-in-the-making codenamed C++1y, has some great new features. The most standout addition in my opinion is the &#8216;return type deduction&#8217; feature which allows functions to use &#8216;auto&#8217; return types that will be deduced at runtime. There are a few limits on this functionality however. Recursion can only happen if there is at least one return statement that can be evaluated to a non-auto type. For example: \/\/ this factorial works auto factorial(int i) { if(i == 0&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[72],"tags":[11],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++ 2014: auto return deduction and more! - Jacob N Calvert<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jacobncalvert.com\/blog-archive\/2014\/07\/15\/c-2014-auto-return-deduction-and-more\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ 2014: auto return deduction and more! - Jacob N Calvert\" \/>\n<meta property=\"og:description\" content=\"The new C++ standard-in-the-making codenamed C++1y, has some great new features. The most standout addition in my opinion is the &#8216;return type deduction&#8217; feature which allows functions to use &#8216;auto&#8217; return types that will be deduced at runtime. There are a few limits on this functionality however. Recursion can only happen if there is at least one return statement that can be evaluated to a non-auto type. For example: \/\/ this factorial works auto factorial(int i) { if(i == 0&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jacobncalvert.com\/blog-archive\/2014\/07\/15\/c-2014-auto-return-deduction-and-more\/\" \/>\n<meta property=\"og:site_name\" content=\"Jacob N Calvert\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-16T01:50:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-02-10T21:59:32+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/#website\",\"url\":\"https:\/\/jacobncalvert.com\/blog-archive\/\",\"name\":\"Jacob N Calvert\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/jacobncalvert.com\/blog-archive\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/2014\/07\/15\/c-2014-auto-return-deduction-and-more\/#webpage\",\"url\":\"https:\/\/jacobncalvert.com\/blog-archive\/2014\/07\/15\/c-2014-auto-return-deduction-and-more\/\",\"name\":\"C++ 2014: auto return deduction and more! - Jacob N Calvert\",\"isPartOf\":{\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/#website\"},\"datePublished\":\"2014-07-16T01:50:53+00:00\",\"dateModified\":\"2018-02-10T21:59:32+00:00\",\"author\":{\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/#\/schema\/person\/f4b22a996d41bf09ed2bbe22912a8c8a\"},\"breadcrumb\":{\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/2014\/07\/15\/c-2014-auto-return-deduction-and-more\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jacobncalvert.com\/blog-archive\/2014\/07\/15\/c-2014-auto-return-deduction-and-more\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/2014\/07\/15\/c-2014-auto-return-deduction-and-more\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/\",\"url\":\"https:\/\/jacobncalvert.com\/blog-archive\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/2014\/07\/15\/c-2014-auto-return-deduction-and-more\/#webpage\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/#\/schema\/person\/f4b22a996d41bf09ed2bbe22912a8c8a\",\"name\":\"Jacob\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/64a2dd1c00cb39dfc19bb1204c87efbc?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/64a2dd1c00cb39dfc19bb1204c87efbc?s=96&d=mm&r=g\",\"caption\":\"Jacob\"},\"sameAs\":[\"https:\/\/jacobncalvert.com\"],\"url\":\"https:\/\/jacobncalvert.com\/blog-archive\/author\/jcalvert\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/posts\/172"}],"collection":[{"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/comments?post=172"}],"version-history":[{"count":3,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/posts\/172\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/posts\/172\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/media?parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/categories?post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/tags?post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}