{"id":602,"date":"2018-10-31T17:23:56","date_gmt":"2018-10-31T17:23:56","guid":{"rendered":"https:\/\/yazilimperver.net\/?p=602"},"modified":"2019-01-07T19:08:54","modified_gmt":"2019-01-07T19:08:54","slug":"english-weekly-c-3-if-switch-init-statements","status":"publish","type":"post","link":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/","title":{"rendered":"[:tr]Haftal\u0131k C++ 3 &#8211; if\/switch ilklendirme ifadeleri[:en]Weekly C++ 3 &#8211; if\/switch init-statements[:]"},"content":{"rendered":"<p>[:tr]Bu yaz\u0131mda, C++ 17 ile gelen ve de\u011fi\u015fkenlerin tan\u0131ml\u0131 oldu\u011fu kapsamlar\u0131 k\u0131s\u0131tlamam\u0131za yard\u0131mc\u0131 olacak yeni bir kapsam mekanizmas\u0131ndan bahsedece\u011fim. Bildi\u011finiz gibi, tan\u0131mlad\u0131\u011f\u0131n\u0131z de\u011fi\u015fkenlerin kapsamlar\u0131n\u0131 olabildi\u011fince k\u00fc\u00e7\u00fck olacak (yani ge\u00e7erli oldu\u011fu kapsam\u0131 azaltmak) \u015fekilde tan\u0131mlamak tavsiye edilen bir y\u00f6ntemdir.<\/p>\n<blockquote><p>De\u011fi\u015fkenleri olabildi\u011fince k\u00fc\u00e7\u00fck bir kapsam i\u00e7erisinde ve ilk kullan\u0131ma yak\u0131n tan\u0131mlay\u0131n.<\/p><\/blockquote>\n<p>Peki neden? Her ne kadar \u00e7o\u011fu derleyici siz de\u011fi\u015fkeni tan\u0131mlay\u0131p kullanmad\u0131\u011f\u0131n\u0131zda sizi uyarsa da, her bir de\u011fi\u015fken tan\u0131mlad\u0131\u011f\u0131 kapsam\u0131 kirletmekte ve daha i\u00e7 kapsamlardaki ayn\u0131 isimli de\u011fi\u015fkenleri \u00f6rtebilir (buna ayr\u0131ca g\u00f6lgeleme veya isim gizleme de denir). Bundan daha da \u00f6nemlisi bu tarz tan\u0131mlamalar kodun karma\u015f\u0131kl\u0131\u011f\u0131n\u0131 artt\u0131rmakta ve onu daha az okunur, idamesi zor bir hale getirebilir. A\u015fa\u011f\u0131da bu durumu g\u00f6steren \u00e7ok basit bir \u00f6rne\u011fi g\u00f6rebilirsiniz:<\/p>\n<pre class=\"lang:c++ decode:true\">void foo()\r\n{\r\n   int i = 7;\r\n\r\n   \/\/ i bu kapsamda kullan\u0131lm\u0131yor\r\n   if (someCondition)\r\n   {\r\n      \/\/ i sadece bu if blo\u011fu i\u00e7inde kullan\u0131l\u0131yor\r\n   }\r\n   \/\/ i burada kullan\u0131lm\u0131yor ve ihtiya\u00e7 duyulmuyor!\r\n}<\/pre>\n<p>Yukar\u0131daki kullan\u0131m yerine, a\u015fa\u011f\u0131daki kod kullan\u0131lmal\u0131d\u0131r.<\/p>\n<pre class=\"lang:c++ decode:true\">void foo()\r\n{\r\n    \/\/ i nin burada kullan\u0131lmas\u0131na ihtiya\u00e7 yok o zaman burada tan\u0131mlamayal\u0131m\r\n    if (someCondition)\r\n    {\r\n        int i = 7;\r\n        \/\/ i sadece bu if blo\u011fu i\u00e7inde kullan\u0131l\u0131yor\r\n     }\r\n    \/\/ i burada kullan\u0131lm\u0131yor ve ihtiya\u00e7 duyulmuyor!\r\n}<\/pre>\n<p>C++ 17 ile birlikte bu tarz kapsam k\u0131s\u0131tlamay\u0131 kolayla\u015ft\u0131ran &#8220;<em>ilklendirmeli if\/switch ifadeleri<\/em>&#8221; mekanizmas\u0131 dile eklendi. A\u015fa\u011f\u0131daki standarda ili\u015fkin kaynakta bu mekanizmaya ili\u015fkin detaylar\u0131 bulabilirsiniz.<\/p>\n<p>For ifadelerine benzer \u015fekilde, if\/switch parantezleri i\u00e7erisinde sadece bu ifadelere ili\u015fkin bloklar (if\/else, switch\/case) i\u00e7erisinde ge\u00e7erli olacak ilklendirmeleri tan\u0131mlayabiliyorsunuz. A\u015fa\u011f\u0131da geleneksel ve yeni yakla\u015f\u0131m\u0131 g\u00f6rebilirsiniz:<\/p>\n<pre class=\"lang:c++ decode:true\">\/\/ Onceki if ifadesi kullan\u0131m\u0131:\r\n\/\/ Bu ilklendirmeler burada yap\u0131l\u0131yordu ce if bloklar\u0131 sonras\u0131nda da ula\u015f\u0131labilirdi\r\ninit-statement\r\n\r\nif (condition)\r\n{\r\n    \/\/ Bir \u015feyler yapal\u0131m\r\n}\r\nelse\r\n{\r\n    \/\/ Ya da ba\u015fka \u015feyler yapal\u0131m\r\n}\r\n\r\n\/\/ C++ 17 yakla\u015f\u0131m\u0131\r\n\/\/ ilklendirmeler halen var ama if ifadesi parantezi i\u00e7erisinde ta\u015f\u0131n\u0131yor\r\n\/\/ ve if\/else bloklar\u0131 d\u0131\u015f\u0131nda ula\u015f\u0131labilir de\u011filler\r\nif (init-statement; condition)\r\n{ \r\n    \/\/ Bir \u015feyler yapal\u0131m\r\n}\r\nelse\r\n{\r\n    \/\/ Ya da ba\u015fka \u015feyler yapal\u0131m\r\n}\r\n\r\n\/\/ Benzer \u015fekilde switch ifadesi i\u00e7in de ilgili ilklendirmeler yap\u0131labilir\r\nswitch (initial-statement; variable) \r\n{\r\n....\r\n\/\/ cases\r\n}<\/pre>\n<p>Bu mekanizmaya ili\u015fkin ba\u015fka bir \u00f6rnek kullan\u0131ma bakal\u0131m hele:<\/p>\n<pre class=\"lang:c++ decode:true\">#include &lt;iostream&gt;\r\n#include &lt;cstdlib&gt;\r\nusing namespace std;\r\n\r\nint main() \r\n{\r\n    \/\/ Rastgele say\u0131 \u00fcretelim hele bir\r\n    srand(time(NULL));\r\n\r\n    \/\/ C++17 \u00f6ncesi\r\n    int i = 2;\r\n    if ( i % 2 == 0)\r\n        cout &lt;&lt; i &lt;&lt; \" bir cift sayi\" &lt;&lt; endl;\r\n\r\n    \/\/ C++17 sonrasi\r\n    \/\/ if(init-statement; condition)\r\n    \/\/ i ismi sadece if blogu icinde ulasilabilir\r\n    if (int i = 4; i % 2 == 0 )\r\n    {\r\n        cout &lt;&lt; i &lt;&lt; \" bir cift sayi\" &lt;&lt; endl;\r\n    }\r\n\r\n    \/\/ Baska bir ornek\r\n    \/\/ C++17 oncesi\r\n    char c = getchar();\r\n    switch (c)\r\n    {\r\n        case 'a': move_left(); break;\r\n        case 's': move_back(); break;\r\n        case 'w': move_fwd(); break;\r\n        case 'd': move_right(); break;\r\n        case 'q': quit_game(); break;\r\n    }\r\n    \/\/ c degiskeni halen ulasilabilir\r\n\r\n    \/\/ C++17 sonrasi\r\n    \/\/ switch(init;variable)\r\n    switch (char c2 (getchar()); c2)\r\n    {\r\n        case 'a': move_left(); break;\r\n        case 's': move_back(); break;\r\n        case 'w': move_fwd(); break;\r\n        case 'd': move_right(); break;\r\n        case 'q': quit_game(); break;\r\n    }\r\n\r\n    \/\/ c2 artik ulasilabilir de\u011fil\r\n    return 0;\r\n}<\/pre>\n<p>Bu mekanizman\u0131n bir di\u011fer yayg\u0131n kullan\u0131m\u0131 konteynerler ile kullan\u0131lan iterat\u00f6rler ile oluyor:<\/p>\n<pre class=\"lang:c++ decode:true\">#include &lt;cstddef&gt;\r\n#include &lt;map&gt;\r\n#include &lt;string&gt;\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n    \/\/ Ya\u015f ve isim cifti\r\n    map&lt;string, size_t&gt; nameCounters { {\"Ahmet\", 5}, {\"Begum\", 12}, {\"Fatih\", 3} };\r\n\r\n    \/\/ C++17 Oncesi\r\n    auto result = nameCounters.find(\"Ahmet\");\r\n\r\n    if (result != cend(nameCounters))\r\n        cout &lt;&lt; \"Adet: \" &lt;&lt; result-&gt;second &lt;&lt; endl;\r\n\r\n    \/\/ result halen ula\u015f\u0131labilir ve kapsam\u0131 kirletiyor\r\n\r\n    \/\/ C++17 sonrasi\r\n    \/\/ Kirletme artik yok :)\r\n    if (auto result = nameCounters.find(\"Ahmet\"); result != cend(nameCounters))\r\n        cout &lt;&lt; \"Adet: \" &lt;&lt; result-&gt;second &lt;&lt; endl;\r\n}<\/pre>\n<p>A\u015fa\u011f\u0131da da normalde \u00e7ok \u00e7irkinle\u015febilecek bir kodun nas\u0131l sade bir hale gelebilece\u011fini g\u00f6receksiniz:<\/p>\n<pre class=\"lang:c++ decode:true\">#include &lt;iostream&gt;\r\n#include &lt;string&gt;\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n    const string myString = \"Hello World\";\r\n\r\n    \/\/ C++ 17 oncesi limitlenmemis kapsam durumu\r\n    auto it = myString.find(\"Hello\");\r\n    if (it != string::npos)\r\n        cout &lt;&lt; it &lt;&lt; \" Hello\\n\";\r\n\r\n    auto it2 = myString.find(\"World\");\r\n    if (it2 != string::npos)\r\n        cout &lt;&lt; it2 &lt;&lt; \" World\\n\";\r\n\r\n    \/\/ C++ 17 oncesi limitlenmis kapsam durumu\r\n    \/\/ ekstra k\u00fcme i\u015fareti ile it diger kapsamlara a\u00e7\u0131lm\u0131yor ama kod ta pek g\u00fczel olmad\u0131 sanki\r\n    {\r\n        auto it = myString.find(\"Hello\");\r\n        if (it != string::npos)\r\n            cout &lt;&lt; \"Hello\\n\";\r\n    }\r\n\r\n    {\r\n        auto it = myString.find(\"World\");\r\n        if (it != string::npos)\r\n            cout &lt;&lt; \"World\\n\";\r\n    }\r\n\r\n    \/\/ C++17 sonras\u0131\r\n    \/\/ Sizce hangisi daha g\u00fczel :)\r\n    if (const auto it = myString.find(\"Hello\"); it != string::npos)\r\n        cout &lt;&lt; it &lt;&lt; \" Hello\\n\";\r\n\r\n    if (const auto it = myString.find(\"World\"); it != string::npos)\r\n        cout &lt;&lt; it &lt;&lt; \" World\\n\";\r\n}<\/pre>\n<p>Bu mekanizma ayr\u0131ca kritik alanlarda kilitleme i\u00e7in de kullan\u0131labilir:<\/p>\n<pre class=\"lang:c++ decode:true\">\/\/ If blogu sonra kilit otomatik olarak serbest b\u0131rak\u0131lacak\r\nif (std::lock_guard&lt;std::mutex&gt; lg {my_mutex}; some_condition)\r\n{\r\n     \/\/ Do something\r\n}<\/pre>\n<p>Son olarak, \u00f6zellikle \u00e7\u0131kt\u0131 parametreleri i\u00e7eren API&#8217;lere i\u00e7in de bu mekanizma a\u015fa\u011f\u0131daki gibi kullan\u0131labilir:<\/p>\n<pre class=\"lang:c++ decode:true\">if (DWORD rcCode; ExampleAPI(inputParam, &amp;rcCode))\r\n{\r\n      cout &lt;&lt; \"API donus degeri: \" &lt;&lt; rcCode &lt;&lt; endl;\r\n}\r\n\/\/ rcCode if blogu d\u0131s\u0131nda ulas\u0131labilir degil<\/pre>\n<p>Bu mekanizmaya ili\u015fkin bir di\u011fer kullan\u0131m daha var ama onu da in\u015fallah yeni bir C++ 17 \u00f6zelli\u011fi olan &#8220;structured binding&#8221; &#8216;i aktaraca\u011f\u0131m haftal\u0131k C++ yaz\u0131ma sakl\u0131yorum.<\/p>\n<p>O vakte kadar, kendinize iyi bak\u0131n!<\/p>\n<h2><span style=\"color: #3366ff;\"><strong>Kaynaklar<\/strong><\/span><\/h2>\n<ul>\n<li><strong><span style=\"color: #339966;\"><a style=\"color: #339966;\" href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/scope\">https:\/\/en.cppreference.com\/w\/cpp\/language\/scope<\/a><\/span><\/strong><\/li>\n<li><strong><span style=\"color: #339966;\"><a style=\"color: #339966;\" href=\"https:\/\/www.tutorialspoint.com\/cplusplus\/cpp_variable_scope.htm\">https:\/\/www.tutorialspoint.com\/cplusplus\/cpp_variable_scope.htm<\/a><\/span><\/strong><\/li>\n<li><strong><span style=\"color: #339966;\"><a style=\"color: #339966;\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/b7kfh662.aspx\">https:\/\/msdn.microsoft.com\/en-us\/library\/b7kfh662.aspx<\/a><\/span><\/strong><\/li>\n<li><strong><span style=\"color: #339966;\"><a style=\"color: #339966;\" href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2016\/p0305r0.html\">http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2016\/p0305r0.html<\/a><\/span><\/strong><\/li>\n<\/ul>\n<p>[:en]In this post, we are going to explore a new scoping mechanism which let us to limit scope of a variable further. As you may now, it is always a good practice to reduce the scope of a variable which usually stated as follow so that it is only visible in the intended scope:<\/p>\n<blockquote><p>Define variables in the smallest scope and as close to the first use as possible.<\/p><\/blockquote>\n<p>So why do we do that? Although most modern compilers will warn you about this but you may declare a variable but never use that variable which clutter name space and may hidden other variables (which is also called name hiding or shadowing). This may then increase code complexity and make it less readable and hard to maintain. A very simple and obvious example is provided below:<\/p>\n<pre class=\"lang:c++ decode:true\">void foo()\r\n{\r\n   int i = 7;\r\n\r\n   \/\/ i is not used here\r\n   if (someCondition)\r\n   {\r\n      \/\/ i is used only within this block\r\n   }\r\n   \/\/ i is not used here and not needed!\r\n}<\/pre>\n<p>Instead of above usage, following code should be used.<\/p>\n<pre class=\"lang:c++ decode:true\">void foo()\r\n{\r\n    \/\/ i can not be used here (no need to also)\r\n    if (someCondition)\r\n    {\r\n        int i = 7;\r\n        \/\/ i is used only within this block\r\n     }\r\n     \/\/ i can not be used here\r\n}<\/pre>\n<p>Well, a new mechanism is provided with C++ 17 that will help you to limit the scope of variables which are `<em>if and switch with initializers<\/em>`. You can find the corresponding standard page in references section.<br \/>\nSimilar to for statements, now you can define initialization statements in if\/switch paranthesises that will only applicable to <em>if\/else<\/em> and <em>switch\/case<\/em> blocks, but not outside. Previous usage of if\/switch statements are as follow:<\/p>\n<pre class=\"lang:c++ decode:true \">\/\/ Previous if statement usage:\r\n\/\/ need to be defined here to be used in if scopes\r\ninit-statement\r\n\r\nif (condition)\r\n{\r\n    \/\/ Do Something\r\n}\r\nelse\r\n{\r\n    \/\/ Do Something else\r\n}\r\n\r\n\/\/ C++ 17 way of doing it\r\n\/\/ init-statements are still exist\r\n\/\/ but with init statements now we can use following:\r\nif (init-statement; condition)\r\n{\r\n    \/\/ Do Something\r\n}\r\nelse\r\n{\r\n    \/\/ Do Something else\r\n}\r\n\r\n\/\/ Variables defined in init statements can not be used here\r\nswitch (initial-statement; variable) \r\n{\r\n....\r\n\/\/ cases\r\n}<\/pre>\n<p>Below code sample illustrates an example usage of this:<\/p>\n<pre class=\"lang:c++ decode:true \">\/\/Program to demonstrate init if-else\r\n\/\/ feature introduced in C++17\r\n#include &lt;iostream&gt;\r\n#include &lt;cstdlib&gt;\r\nusing namespace std;\r\n\r\nint main() \r\n{\r\n    \/\/ Set up rand function to be used\r\n    \/\/ later in program\r\n    srand(time(NULL));\r\n\r\n    \/\/ Before C++17\r\n    int i = 2;\r\n    if ( i % 2 == 0)\r\n        cout &lt;&lt; i &lt;&lt; \" is even number\" &lt;&lt; endl;\r\n\r\n    \/\/ After C++17\r\n    \/\/ if(init-statement; condition)\r\n    \/\/ i name is only limited in if scope\r\n    if (int i = 4; i % 2 == 0 )\r\n    {\r\n        cout &lt;&lt; i &lt;&lt; \" is even number\" &lt;&lt; endl;\r\n    }\r\n\r\n    \/\/ Another example about getting input\r\n    \/\/ Before C++17\r\n    char c = getchar();\r\n    switch (c)\r\n    {\r\n        case 'a': move_left(); break;\r\n        case 's': move_back(); break;\r\n        case 'w': move_fwd(); break;\r\n        case 'd': move_right(); break;\r\n        case 'q': quit_game(); break;\r\n    }\r\n    \/\/ c still available here\r\n\r\n    \/\/ After C++17\r\n    \/\/ switch(init;variable)\r\n    switch (char c (getchar()); c)\r\n    {\r\n        case 'a': move_left(); break;\r\n        case 's': move_back(); break;\r\n        case 'w': move_fwd(); break;\r\n        case 'd': move_right(); break;\r\n        case 'q': quit_game(); break;\r\n    }\r\n\r\n    \/\/ c is not usable\/available here\r\n    return 0;\r\n}<\/pre>\n<p>Another common usage is for container iterators such as below:<\/p>\n<pre class=\"lang:c++ decode:true \">#include &lt;cstddef&gt;\r\n#include &lt;map&gt;\r\n#include &lt;string&gt;\r\n#include &lt;iostream&gt;\r\n\r\nint main()\r\n{\r\n    \/\/ A map container with name and age pair\r\n    std::map&lt;std::string, size_t&gt; nameCounters { {\"Ahmet\", 5}, {\"Begum\", 12}, {\"Fatih\", 3} };\r\n\r\n    \/\/ Before C++17\r\n    auto result = nameCounters.find(\"Ahmet\");\r\n\r\n    if (result != cend(nameCounters))\r\n        std::cout &lt;&lt; \"Count: \" &lt;&lt; result-&gt;second &lt;&lt; std::endl;\r\n\r\n    \/\/ result still can be used here and pollute the scope\r\n\r\n    \/\/ After C++17\r\n    \/\/ No redundant pollution :)\r\n    if (auto result = nameCounters.find(\"Ahmet\"); result != cend(nameCounters))\r\n        std::cout &lt;&lt; \"Count: \" &lt;&lt; result-&gt;second &lt;&lt; std::endl;\r\n}<\/pre>\n<p>Below code sample also illustrates how can this make your code ugly \ud83d\ude41<\/p>\n<pre class=\"lang:c++ decode:true \">#include &lt;iostream&gt;\r\n#include &lt;string&gt;\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n    const string myString = \"Hello World\";\r\n\r\n    \/\/ Before C++ 17 unlimited scope case\r\n    auto it = myString.find(\"Hello\");\r\n    if (it != string::npos)\r\n        cout &lt;&lt; it &lt;&lt; \" Hello\\n\";\r\n\r\n    auto it2 = myString.find(\"World\");\r\n    if (it2 != string::npos)\r\n        cout &lt;&lt; it2 &lt;&lt; \" World\\n\";\r\n\r\n    \/\/ Before C++ 17 limited scope case\r\n    \/\/ additional enclosing scope so 'it' doesn't 'leak'\r\n    {\r\n        auto it = myString.find(\"Hello\");\r\n        if (it != string::npos)\r\n            cout &lt;&lt; \"Hello\\n\";\r\n    }\r\n\r\n    {\r\n        auto it = myString.find(\"World\");\r\n        if (it != string::npos)\r\n            cout &lt;&lt; \"World\\n\";\r\n    }\r\n\r\n    \/\/ New way of doing it. Which one do you prefer?\r\n    \/\/ C++17 with init if:\r\n    if (const auto it = myString.find(\"Hello\"); it != string::npos)\r\n        cout &lt;&lt; it &lt;&lt; \" Hello\\n\";\r\n\r\n    if (const auto it = myString.find(\"World\"); it != string::npos)\r\n        cout &lt;&lt; it &lt;&lt; \" World\\n\";\r\n}<\/pre>\n<p>This can also be used to limit the scopes of critical sections such as below:<\/p>\n<pre class=\"lang:c++ decode:true\">\/\/ After if lock will be released (unlocked)\r\nif (std::lock_guard&lt;std::mutex&gt; lg {my_mutex}; some_condition)\r\n{\r\n     \/\/ Do something\r\n}<\/pre>\n<p>Finally, it can also be used for APIs that return output parameters as follow:<\/p>\n<pre class=\"lang:c++ decode:true \">if (DWORD rcCode; ExampleAPI(inputParam, &amp;rcCode))\r\n{\r\n      cout &lt;&lt; \"Return code of API was: \" &lt;&lt; rcCode &lt;&lt; endl;\r\n}\r\n\/\/ No useless rcCode variable outside the if-conditional<\/pre>\n<p>There is also another usage but I left it for next week where I am planning to cover another feature of C++ 17, structured binding.<\/p>\n<p>Take care of yourselves!<\/p>\n<h2><span style=\"color: #3366ff;\"><strong>References<\/strong><\/span><\/h2>\n<ul>\n<li><strong><span style=\"color: #339966;\"><a style=\"color: #339966;\" href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/scope\">https:\/\/en.cppreference.com\/w\/cpp\/language\/scope<\/a><\/span><\/strong><\/li>\n<li><strong><span style=\"color: #339966;\"><a style=\"color: #339966;\" href=\"https:\/\/www.tutorialspoint.com\/cplusplus\/cpp_variable_scope.htm\">https:\/\/www.tutorialspoint.com\/cplusplus\/cpp_variable_scope.htm<\/a><\/span><\/strong><\/li>\n<li><strong><span style=\"color: #339966;\"><a style=\"color: #339966;\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/b7kfh662.aspx\">https:\/\/msdn.microsoft.com\/en-us\/library\/b7kfh662.aspx<\/a><\/span><\/strong><\/li>\n<li><strong><span style=\"color: #339966;\"><a style=\"color: #339966;\" href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2016\/p0305r0.html\">http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2016\/p0305r0.html<\/a><\/span><\/strong><\/li>\n<\/ul>\n<p>[:]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[:tr]Bu yaz\u0131mda, C++ 17 ile gelen ve de\u011fi\u015fkenlerin tan\u0131ml\u0131 oldu\u011fu kapsamlar\u0131 k\u0131s\u0131tlamam\u0131za yard\u0131mc\u0131 olacak yeni bir kapsam mekanizmas\u0131ndan bahsedece\u011fim. Bildi\u011finiz gibi, tan\u0131mlad\u0131\u011f\u0131n\u0131z de\u011fi\u015fkenlerin kapsamlar\u0131n\u0131 olabildi\u011fince k\u00fc\u00e7\u00fck olacak (yani ge\u00e7erli oldu\u011fu kapsam\u0131 azaltmak) \u015fekilde tan\u0131mlamak tavsiye edilen bir y\u00f6ntemdir. De\u011fi\u015fkenleri olabildi\u011fince k\u00fc\u00e7\u00fck bir kapsam i\u00e7erisinde ve ilk kullan\u0131ma yak\u0131n tan\u0131mlay\u0131n. Peki neden? Her ne kadar \u00e7o\u011fu&#8230; <a class=\"more-link\" href=\"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/\">Continue reading <span class=\"meta-nav\">&#8594;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":174,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"dsgo_overlay_header":false,"dsgo_overlay_header_text_color":"","dsgo_overlay_skip_top_bar":false,"_designsetgo_exclude_llms":false,"footnotes":""},"categories":[1],"tags":[234,229,237,235,231,233,42,232,230,203,236],"class_list":["post-602","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-c-17","tag-if","tag-if-and-switch-with-initializers","tag-if-initializer","tag-initializer","tag-limited-scope","tag-modern-c","tag-scope","tag-switch","tag-weekly","tag-weekly-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[:tr]Haftal\u0131k C++ 3 - if\/switch ilklendirme ifadeleri[:en]Weekly C++ 3 - if\/switch init-statements[:] - Yaz\u0131l\u0131mperver&#039;in D\u00fcnyas\u0131<\/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:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/\" \/>\n<meta property=\"og:locale\" content=\"tr_TR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[:tr]Haftal\u0131k C++ 3 - if\/switch ilklendirme ifadeleri[:en]Weekly C++ 3 - if\/switch init-statements[:] - Yaz\u0131l\u0131mperver&#039;in D\u00fcnyas\u0131\" \/>\n<meta property=\"og:description\" content=\"[:tr]Bu yaz\u0131mda, C++ 17 ile gelen ve de\u011fi\u015fkenlerin tan\u0131ml\u0131 oldu\u011fu kapsamlar\u0131 k\u0131s\u0131tlamam\u0131za yard\u0131mc\u0131 olacak yeni bir kapsam mekanizmas\u0131ndan bahsedece\u011fim. Bildi\u011finiz gibi, tan\u0131mlad\u0131\u011f\u0131n\u0131z de\u011fi\u015fkenlerin kapsamlar\u0131n\u0131 olabildi\u011fince k\u00fc\u00e7\u00fck olacak (yani ge\u00e7erli oldu\u011fu kapsam\u0131 azaltmak) \u015fekilde tan\u0131mlamak tavsiye edilen bir y\u00f6ntemdir. De\u011fi\u015fkenleri olabildi\u011fince k\u00fc\u00e7\u00fck bir kapsam i\u00e7erisinde ve ilk kullan\u0131ma yak\u0131n tan\u0131mlay\u0131n. Peki neden? Her ne kadar \u00e7o\u011fu... Continue reading &#8594;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/\" \/>\n<meta property=\"og:site_name\" content=\"Yaz\u0131l\u0131mperver&#039;in D\u00fcnyas\u0131\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-31T17:23:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-01-07T19:08:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/yazilimperver.net\/wp-content\/uploads\/2017\/12\/FeaturedImage-e1580417052514.png\" \/>\n\t<meta property=\"og:image:width\" content=\"32\" \/>\n\t<meta property=\"og:image:height\" content=\"32\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"yaz\u0131l\u0131mperver\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Yazan:\" \/>\n\t<meta name=\"twitter:data1\" content=\"yaz\u0131l\u0131mperver\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tahmini okuma s\u00fcresi\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 dakika\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/\"},\"author\":{\"name\":\"yaz\u0131l\u0131mperver\",\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/#\\\/schema\\\/person\\\/534a27860d56170658018ac4c6f1af16\"},\"headline\":\"[:tr]Haftal\u0131k C++ 3 &#8211; if\\\/switch ilklendirme ifadeleri[:en]Weekly C++ 3 &#8211; if\\\/switch init-statements[:]\",\"datePublished\":\"2018-10-31T17:23:56+00:00\",\"dateModified\":\"2019-01-07T19:08:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/\"},\"wordCount\":775,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/#\\\/schema\\\/person\\\/534a27860d56170658018ac4c6f1af16\"},\"image\":{\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/yazilimperver.net\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/FeaturedImage-e1580417052514.png\",\"keywords\":[\"c++ 17\",\"if\",\"if and switch with initializers\",\"if initializer\",\"initializer\",\"limited scope\",\"Modern C++\",\"scope\",\"switch\",\"Weekly\",\"weekly c++\"],\"articleSection\":[\"Uncategorized\"],\"inLanguage\":\"tr\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/\",\"url\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/\",\"name\":\"[:tr]Haftal\u0131k C++ 3 - if\\\/switch ilklendirme ifadeleri[:en]Weekly C++ 3 - if\\\/switch init-statements[:] - Yaz\u0131l\u0131mperver&#039;in D\u00fcnyas\u0131\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/yazilimperver.net\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/FeaturedImage-e1580417052514.png\",\"datePublished\":\"2018-10-31T17:23:56+00:00\",\"dateModified\":\"2019-01-07T19:08:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/#breadcrumb\"},\"inLanguage\":\"tr\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"tr\",\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/#primaryimage\",\"url\":\"https:\\\/\\\/yazilimperver.net\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/FeaturedImage-e1580417052514.png\",\"contentUrl\":\"https:\\\/\\\/yazilimperver.net\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/FeaturedImage-e1580417052514.png\",\"width\":32,\"height\":32},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/index.php\\\/2018\\\/10\\\/31\\\/english-weekly-c-3-if-switch-init-statements\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Ana sayfa\",\"item\":\"https:\\\/\\\/yazilimperver.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Haftal\u0131k C++ 3 &#8211; if\\\/switch ilklendirme ifadeleri\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/#website\",\"url\":\"https:\\\/\\\/yazilimperver.net\\\/\",\"name\":\"Yaz\u0131l\u0131mperver'in D\u00fcnyas\u0131\",\"description\":\"Payla\u015fmak g\u00fczeldir.\",\"publisher\":{\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/#\\\/schema\\\/person\\\/534a27860d56170658018ac4c6f1af16\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/yazilimperver.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"tr\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/#\\\/schema\\\/person\\\/534a27860d56170658018ac4c6f1af16\",\"name\":\"yaz\u0131l\u0131mperver\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"tr\",\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/cropped-OnlyIcon-1.png\",\"url\":\"https:\\\/\\\/yazilimperver.net\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/cropped-OnlyIcon-1.png\",\"contentUrl\":\"https:\\\/\\\/yazilimperver.net\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/cropped-OnlyIcon-1.png\",\"width\":512,\"height\":512,\"caption\":\"yaz\u0131l\u0131mperver\"},\"logo\":{\"@id\":\"https:\\\/\\\/yazilimperver.net\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/cropped-OnlyIcon-1.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[:tr]Haftal\u0131k C++ 3 - if\/switch ilklendirme ifadeleri[:en]Weekly C++ 3 - if\/switch init-statements[:] - Yaz\u0131l\u0131mperver&#039;in D\u00fcnyas\u0131","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/","og_locale":"tr_TR","og_type":"article","og_title":"[:tr]Haftal\u0131k C++ 3 - if\/switch ilklendirme ifadeleri[:en]Weekly C++ 3 - if\/switch init-statements[:] - Yaz\u0131l\u0131mperver&#039;in D\u00fcnyas\u0131","og_description":"[:tr]Bu yaz\u0131mda, C++ 17 ile gelen ve de\u011fi\u015fkenlerin tan\u0131ml\u0131 oldu\u011fu kapsamlar\u0131 k\u0131s\u0131tlamam\u0131za yard\u0131mc\u0131 olacak yeni bir kapsam mekanizmas\u0131ndan bahsedece\u011fim. Bildi\u011finiz gibi, tan\u0131mlad\u0131\u011f\u0131n\u0131z de\u011fi\u015fkenlerin kapsamlar\u0131n\u0131 olabildi\u011fince k\u00fc\u00e7\u00fck olacak (yani ge\u00e7erli oldu\u011fu kapsam\u0131 azaltmak) \u015fekilde tan\u0131mlamak tavsiye edilen bir y\u00f6ntemdir. De\u011fi\u015fkenleri olabildi\u011fince k\u00fc\u00e7\u00fck bir kapsam i\u00e7erisinde ve ilk kullan\u0131ma yak\u0131n tan\u0131mlay\u0131n. Peki neden? Her ne kadar \u00e7o\u011fu... Continue reading &#8594;","og_url":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/","og_site_name":"Yaz\u0131l\u0131mperver&#039;in D\u00fcnyas\u0131","article_published_time":"2018-10-31T17:23:56+00:00","article_modified_time":"2019-01-07T19:08:54+00:00","og_image":[{"width":32,"height":32,"url":"https:\/\/yazilimperver.net\/wp-content\/uploads\/2017\/12\/FeaturedImage-e1580417052514.png","type":"image\/png"}],"author":"yaz\u0131l\u0131mperver","twitter_card":"summary_large_image","twitter_misc":{"Yazan:":"yaz\u0131l\u0131mperver","Tahmini okuma s\u00fcresi":"10 dakika"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/#article","isPartOf":{"@id":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/"},"author":{"name":"yaz\u0131l\u0131mperver","@id":"https:\/\/yazilimperver.net\/#\/schema\/person\/534a27860d56170658018ac4c6f1af16"},"headline":"[:tr]Haftal\u0131k C++ 3 &#8211; if\/switch ilklendirme ifadeleri[:en]Weekly C++ 3 &#8211; if\/switch init-statements[:]","datePublished":"2018-10-31T17:23:56+00:00","dateModified":"2019-01-07T19:08:54+00:00","mainEntityOfPage":{"@id":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/"},"wordCount":775,"commentCount":0,"publisher":{"@id":"https:\/\/yazilimperver.net\/#\/schema\/person\/534a27860d56170658018ac4c6f1af16"},"image":{"@id":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/#primaryimage"},"thumbnailUrl":"https:\/\/yazilimperver.net\/wp-content\/uploads\/2017\/12\/FeaturedImage-e1580417052514.png","keywords":["c++ 17","if","if and switch with initializers","if initializer","initializer","limited scope","Modern C++","scope","switch","Weekly","weekly c++"],"articleSection":["Uncategorized"],"inLanguage":"tr","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/","url":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/","name":"[:tr]Haftal\u0131k C++ 3 - if\/switch ilklendirme ifadeleri[:en]Weekly C++ 3 - if\/switch init-statements[:] - Yaz\u0131l\u0131mperver&#039;in D\u00fcnyas\u0131","isPartOf":{"@id":"https:\/\/yazilimperver.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/#primaryimage"},"image":{"@id":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/#primaryimage"},"thumbnailUrl":"https:\/\/yazilimperver.net\/wp-content\/uploads\/2017\/12\/FeaturedImage-e1580417052514.png","datePublished":"2018-10-31T17:23:56+00:00","dateModified":"2019-01-07T19:08:54+00:00","breadcrumb":{"@id":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/#breadcrumb"},"inLanguage":"tr","potentialAction":[{"@type":"ReadAction","target":["https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/"]}]},{"@type":"ImageObject","inLanguage":"tr","@id":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/#primaryimage","url":"https:\/\/yazilimperver.net\/wp-content\/uploads\/2017\/12\/FeaturedImage-e1580417052514.png","contentUrl":"https:\/\/yazilimperver.net\/wp-content\/uploads\/2017\/12\/FeaturedImage-e1580417052514.png","width":32,"height":32},{"@type":"BreadcrumbList","@id":"https:\/\/yazilimperver.net\/index.php\/2018\/10\/31\/english-weekly-c-3-if-switch-init-statements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Ana sayfa","item":"https:\/\/yazilimperver.net\/"},{"@type":"ListItem","position":2,"name":"Haftal\u0131k C++ 3 &#8211; if\/switch ilklendirme ifadeleri"}]},{"@type":"WebSite","@id":"https:\/\/yazilimperver.net\/#website","url":"https:\/\/yazilimperver.net\/","name":"Yaz\u0131l\u0131mperver'in D\u00fcnyas\u0131","description":"Payla\u015fmak g\u00fczeldir.","publisher":{"@id":"https:\/\/yazilimperver.net\/#\/schema\/person\/534a27860d56170658018ac4c6f1af16"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/yazilimperver.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"tr"},{"@type":["Person","Organization"],"@id":"https:\/\/yazilimperver.net\/#\/schema\/person\/534a27860d56170658018ac4c6f1af16","name":"yaz\u0131l\u0131mperver","image":{"@type":"ImageObject","inLanguage":"tr","@id":"https:\/\/yazilimperver.net\/wp-content\/uploads\/2018\/04\/cropped-OnlyIcon-1.png","url":"https:\/\/yazilimperver.net\/wp-content\/uploads\/2018\/04\/cropped-OnlyIcon-1.png","contentUrl":"https:\/\/yazilimperver.net\/wp-content\/uploads\/2018\/04\/cropped-OnlyIcon-1.png","width":512,"height":512,"caption":"yaz\u0131l\u0131mperver"},"logo":{"@id":"https:\/\/yazilimperver.net\/wp-content\/uploads\/2018\/04\/cropped-OnlyIcon-1.png"}}]}},"_links":{"self":[{"href":"https:\/\/yazilimperver.net\/index.php\/wp-json\/wp\/v2\/posts\/602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yazilimperver.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yazilimperver.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yazilimperver.net\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/yazilimperver.net\/index.php\/wp-json\/wp\/v2\/comments?post=602"}],"version-history":[{"count":0,"href":"https:\/\/yazilimperver.net\/index.php\/wp-json\/wp\/v2\/posts\/602\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yazilimperver.net\/index.php\/wp-json\/wp\/v2\/media\/174"}],"wp:attachment":[{"href":"https:\/\/yazilimperver.net\/index.php\/wp-json\/wp\/v2\/media?parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yazilimperver.net\/index.php\/wp-json\/wp\/v2\/categories?post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yazilimperver.net\/index.php\/wp-json\/wp\/v2\/tags?post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}