Archive for the ‘cpp’ Category
The omnipotent arrow operator
Posted on: 28/12/2009
- In: tricks
- 2 Comments
Are you familiar with the new, all-mighty, arrow “–>” operator in C++ ?
#include <iostream>
int main () {
unsigned count = 30;
while (count --> 0) // count goes to zero
std::cout << count << std::endl;
}
- In: boost
- 2 Comments
The future standard extension (some of it is described in the Technical Report on C++ Standard Library Extensions – TR1) is going to include many libraries already contained within boost. One such library is boost’s Smart Pointers.
In this post I would like to show an interesting use-case of the smart_ptr class, through what I consider to be a less commonly known constructor.
Project Euler
Posted on: 14/12/2009
I know I’m a little late, but I’ve only recently discovered the interesting site of projecteuler.net. For anybody not familiar with it, Project Euler is a site offering a vast collection of programming puzzles of mathematical nature for anybody to solve. It has a ranking system for its members, allowing every member to see others’ statistics with solving the offered puzzles. Most of the puzzles are pretty hard, even for the gifted mathematicians among us, and the majority of them can not be solved using brute force methods (it would just take far too long), so usually an efficient algorithm is required. Once you solve a problem you gain access to a forum thread about the problem, its solution, and the various techniques and algorithms other users came up with.
boost::optional and its internals
Posted on: 04/12/2009
- In: boost
- 11 Comments
boost::optional is a very handy generalization of returning a null when there’s nothing to return. Consider a function such as strstr – either the required sub-string is found within the given string, in which case a pointer to it is returned, or a NULL value is returned to indicate that there was no such sub-string. In terms of boost::optional we would either return the same pointer to the occurrence of that sub-string (as before), or we would simply return nothing – no value at all. In this post we will demonstrate the usage of boost::optional and discuss its implementation.
If you ever try to define a public custom operator new while keeping the corresponding delete operator private, you’ll end up unable to compile any code that actually invokes the public operator new. The reasoning is quite interesting.
Suppose you wanted to check the size (in bytes) of a certain type, WITHOUT using the sizeof() operator. How would you do that?
And what is the size of an empty struct (or class), anyway?
ScopeLogger
Posted on: 18/11/2009
- In: snippets
- 13 Comments
The RAII design pattern can be utilized to create simple and intuitive logging facilities, like the one we will present now. Through the useful macro LOG_FUNC, the proposed ScopeLogger will easily create function call graphs at run time, to allow easy debugging and tracking of program execution.
Recent comments