Making HTTP REST Request in C++

Introduction Today, I am going to show you on how to make HTTP request to a REST server using C++ Requests library by Huu Nguyen. Mr Nguyen is heavily influenced by Python Requests design philosoply when writing C++ Requests. Those who had used or familiar with Python Requests, should feel right at home with C++Continue reading “Making HTTP REST Request in C++”

C++11: Compile-time Conditional Types

Introduction C++11 introduces std::conditional to give C++ developer the flexibility to choose a type based on the compile-time condition. If the boolean parameter of the std::conditional is true, then the delved type is class T or else it is class F. Below is an example on how to use std::conditional. Before to use std::conditional, weContinue reading “C++11: Compile-time Conditional Types”

Design Patterns in Modern C++ Book

Just as I was scouring Amazon for new C++ book. I came across this Design Patterns book with examples based on Modern C++ by Dmitri Nesteruk. A quick look at content table uncovers the null object pattern, curiously recurring template pattern and SOLID design principles in addition to the classic design patterns in the GoFContinue reading “Design Patterns in Modern C++ Book”

Use STL copy, Not memcpy to Copy Array

Many C++ developers like to use memcpy() to copy POD arrays to extract the maximum performance during the copy. See the POD structure below. What if a new unsuspecting developer adds a string member and is not aware that the code uses memcpy() to do copying? memcpy() only makes shallow copies. The code no longerContinue reading “Use STL copy, Not memcpy to Copy Array”

Erase-remove Idiom Revisited

Recently, I reread Erase-remove Idiom on classic Effective STL by Scott Meyers, which is dated by now, so I also consulted the same topic on another STL book published in 2017. How to remove elements from container is a common C++ interview question, so you may want to sit up and pay attention here. std::vectorContinue reading “Erase-remove Idiom Revisited”

My IT Certificates

The blog post is for readers who are interested to see my IT certificates. Certified Secure Software Lifecycle Professional(CSSLP) ITIL® Foundation Certificate(ITIL) EC-Council Certified Security Analyst(ECSA) Certified Ethical Hacker(CEH) EC-Council Certified Secure Programmer(ECSP) Project Management Professional(PMP). In Singapore, for Project Managers undertaking a IT project for government, they are required to be PMP certified. IContinue reading “My IT Certificates”

Pythonic Operators on STL Set Algorithms

  Table of Contents Introduction Set Intersection Set Union Set Difference Set Symmetric Difference Superset and Subset “I have no use for all these!” Introduction Ever since I started working with Python and that have gotten me into alot thinking how to redesign my libraries to be pythonic, if I were to implement them fromContinue reading “Pythonic Operators on STL Set Algorithms”

C++ Summing For Loop Benchmark

  Introduction The initial motivation is to find out the overhead of different for-loop types in C++. Code Copy and paste below code into Godbolt Online C++ Compiler to see the generated assembly code. Note: The array or vector are initialized in the benchmark. The simplified code below is for you to copy and pasteContinue reading “C++ Summing For Loop Benchmark”

C++ Tip: Modification Inside const Function

  Introduction There are times where modification inside const member function must be done (for example, to allow for caching or memoization). The mutable keyword and const_cast are well-known in the C++ circles to work around these. The 3rd way is to use a const pointer; we cannot modify the const pointer but we canContinue reading “C++ Tip: Modification Inside const Function”

C++ Tip: Make Your Class Non-Copyable Without Boost

Introduction There are times where an object should never be passed by copy but by reference or pointer. For instance, the class has a data member (like counter or mutex) which should not be duplicated. In this tip, we take a look at 2 techniques which declare the class to be non-copyable without resorting to usingContinue reading “C++ Tip: Make Your Class Non-Copyable Without Boost”