C
Basic use of Tuples C++11
· β˜• 2 min read · πŸ€– Naresh Mehta

Basic use of Tuples in C++11

Tuples are an amazing feature in C++. Tuples are specified inΒ C++11 standard (ISO/IEC 14882:2011), i.e. they are a new introduction in c++11. So if you are more used to traditionalΒ c++, tuples will come as a surprise for you. It happened to me as well and I am not that old (quite yet)! They are a great addition to generic programming and brings C++ to a whole new level of usability. Of course we have had ways to do exactly the same things that tuples does but now that it is a part of the standard language, it makes sense to use this feature instead of cooking something of our own. I see tuples as an important feature like dictionary in python (more or less). Tuples are amazing and you can feel the power when you start using them. Auto types and tuples make a great combination for very nice cool features previously rarely thought of (multiple return values from a function anyone). Anyways, I don’t see people really appreciating the flexibility being provided by our beloved language. Stefan Lavavej (@StefanTLavavej) maintaining the STL implementation, working at @microsoft, has a very nice talk in CPPCon 2016 that I recommend you watch. Check it out below. This is the one that got me interested in tuples.


Ranged Switch Case C++
· β˜• 2 min read · πŸ€– Naresh Mehta

Ranges in C++ Switch Case block

Today, we will do something really stupid! Yes, I am talking about the ranged switch case support that is available in C++. In all the commercial/hobby source code that I have seen, implemented and used, rarely have I come across the ranged switch case use. Most of the code when in need of ranges inside a switch case start using multiple case cascading or (the more niche programmers) resorting to nested if..else blocks!
So much so that when I told one of my co-workers that we can use ranges in C++ switch case, he started laughing (hysterically if I may add). Taken aback, I wanted to see if I have learned stuff wrong. So here it is, just to brush up your basic cpp knowledge and fall in love with it again! Below is the code in ideone ready for you to take for a spin.


Hello World in D! - Part 2
· β˜• 5 min read · πŸ€– Naresh Mehta

As discussed in my post http://www.naresh.se/?p=5, I am trying to do a comparison between programs written in C++ and D. Why I am doing it is a question not to be asked but in any case, I am bored and would like to do something fun. I thought this is the nice way to have fun. We are going to write a Complex class and a main to test it and compare it with D. I am using Code::Blocks and mingW for C++ and Code::Blocks and Digital Mars D compiler for D. Saying that, read the previous post to know how to use Code::Blocks (CB) or RTFM.