Accessing APIs

Please note that this post has been created more than 3 months ago. It might contain inaccurate or stale (or both!) information. Use with caution!

I was curious about all the great sites I know of releasing their API. Twitter, Google, Facebook, Yelp, are only a few examples of websites providing a way to access their services in a programmatic way. In this post, I have investigated a simple but very interesting API, offered by Rotten Tomatoes, a website about movies.

Read More

Use files

Please note that this post has been created more than 3 months ago. It might contain inaccurate or stale (or both!) information. Use with caution!

Recently I’ve found myself in the common situation where I have to open a file and make something with its content. This is a basic task and should present no difficulties to a programmer; I happened, however, to get stuck for a while in search of a good way to carry out this apparently simple task. In particular, I have run into the recent addition of regular expression processing to the STL. Spoiler alert: I was not particularly happy of what I’ve found along the way.

Read More

Time in C++

Please note that this post has been created more than 3 months ago. It might contain inaccurate or stale (or both!) information. Use with caution!

Using time: the chrono header

Until before the introduction of the chrono library in the STL with the C++11 standard, we were forced to deal with time in a couple of ways, notably using Boost or using some wrapper around the time.h library header, from C.

Read More

STL Algorithms, part 4

Please note that this post has been created more than 3 months ago. It might contain inaccurate or stale (or both!) information. Use with caution!

We have seen some examples of usage of the find algorithm, with its variants find_if and find_if_not. In this installment, we are going to see other variants of finding algorithms, plus another algorithm useful when counting items in a sequence, count. Remember that we are still in the realm of non-modifying sequence algorithms (but see the discussion about for_each here).

Read More

STL Algorithms, part 3

Please note that this post has been created more than 3 months ago. It might contain inaccurate or stale (or both!) information. Use with caution!

In the previous posts of this series, we have had a glance at non-modifying sequence algorithms, i.e., the algorithms that are supposed not to modify the elements of a sequence (or at least, the structure of the sequence; see the observations about for_each.

In this installment, as anticipated, we will start looking at the algorithms for searching.

Read More

STL Algorithms, part 2

Please note that this post has been created more than 3 months ago. It might contain inaccurate or stale (or both!) information. Use with caution!

Previously on this blog

In the previous installment, we have introduced three algorithms, all_of, any_of, and none_of, very useful to determine whether a range of elements satisfy some predicate, expressed as a lambda.

In this second episode, we will explore more algorithms offered by the STL. My objective, in the long run, is to cover all of them with examples, and maybe grasp the ideas that might come to my mind during the process. As usual, if you have any doubt or just spot a plain error, I’d greatly appreciate if you let me know.

Read More

STL Algorithms, part 1

Please note that this post has been created more than 3 months ago. It might contain inaccurate or stale (or both!) information. Use with caution!

Why algorithms

Standard algorithms have a prominent value in the C++ standard template library (STL). They present the great advantage of expressing an operation applied on a range of elements in a container. In this series, I am going to review all the algorithms introduced in the C++11 standard, presenting it in digestible chunks, and will provide at least an example of application for each one.

Read More

Lambdas in C++11

Please note that this post has been created more than 3 months ago. It might contain inaccurate or stale (or both!) information. Use with caution!

Lambda expressions have been introduced to C++ with the most recent standard, presented in Section [expr.prim.lambda]. They allow the creation of simple functions without giving them a name. What are they good for? Being simple is not really the point here; the most useful case that I have found in my limited experience has been as a convenient replacement for Functors (also known as Function objects).

In this post, I’ll give a quick introduction to how to use lambdas in your code. In the next installment, I will discuss a small example of functor, and will show side by side a piece of code with functors and its substitution with a clean lambda.

Read More

Write an Interface between your Program and a Shared Object

Please note that this post has been created more than 3 months ago. It might contain inaccurate or stale (or both!) information. Use with caution!

I wanted to share something I’ve been doing for some hours today, in the hope to understand it better. I also hope to receive criticism on this, because there might be a better way to do the same thing, only more elegantly. This is no research problem, as I am sure it has been solved time and again in different contexts; but the whole example, comprising all the pieces put together in this post, is something I have not seen around, and I think it can be of some service if I explain it.

Read More