{"id":16928,"date":"2024-02-18T13:14:21","date_gmt":"2024-02-18T13:14:21","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=16928"},"modified":"2025-03-10T15:34:22","modified_gmt":"2025-03-10T15:34:22","slug":"conceptual-distinction-programming-c","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=16928","title":{"rendered":"Conceptual distinction \u2013 Programming (C++)"},"content":{"rendered":"<p><strong>lvalue vs. rvalue<\/strong><\/p>\n<ul>\n<li>An lvalue is usually on the left side of an assignment and is addressable in the memory.<\/li>\n<li>An rvalue is usually on the right side of an assignment and isn&#8217;t addressable in the memory.<\/li>\n<\/ul>\n<pre>\r\nint i = 42; \/\/ i is an lvalue and 42 an rvalue\r\nint& j = i; \/\/ j is an lvalue reference\r\n<\/pre>\n<hr>\n<p><strong>rvalue vs. universal reference<\/strong><\/p>\n<pre>\r\nvoid f(int&& i);\r\n\/\/ no type deduction --> rvalue reference\r\n\r\ntemplate&lt;typename T&gt;\r\nvoid f(T&& t);\r\n\/\/ type deduction --> universal reference\r\n<\/pre>\n<hr>\n<p><strong>class vs. struct<\/strong><\/p>\n<ul>\n<li>The members of a class per default are private.<\/li>\n<li>The members of a struct per default are public.<\/li>\n<\/ul>\n<hr>\n<p><strong>Deep vs. Shallow copy<\/strong><\/p>\n<ul>\n<li>Deep: Copies the whole object. (e.g. std::vector)<\/li>\n<li>Shallow: Copies just the meta block. (e.g. std::shared_ptr)<\/li>\n<li>Mixed: std::vector&lt;std::shared_ptr&gt;<\/li>\n<\/ul>\n<hr>\n<p><strong>const std::string&#038; vs. std::string_view<\/strong><\/p>\n<p>Both are ways to pass strings around, without copying them.<\/p>\n<ul>\n<li>const std::string&#038;: Old-school (since C++98); Works just for std::string.<\/li>\n<li>std::string_view: New-school (since C++17); Works for any range of characters.<\/li>\n<\/ul>\n<p>Prefer using std::string_view if possible.<\/p>\n<hr>\n<p><strong>const std::function&#038; vs. std::function_ref<\/strong><\/p>\n<p>Both are ways to pass functions around, without copying them.<\/p>\n<ul>\n<li>const std::function&#038;: Old-school (since C++11); Works with every callable type.<\/li>\n<li>std::function_ref: New-school (since C++26); Doesn&#8217;t work for lambdas with captures.<\/li>\n<\/ul>\n<p>Prefer using std::function_ref if possible.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>lvalue vs. rvalue An lvalue is usually on the left side of an assignment and is addressable in the memory.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[27],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/16928"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16928"}],"version-history":[{"count":24,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/16928\/revisions"}],"predecessor-version":[{"id":18559,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/16928\/revisions\/18559"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16928"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}