cplusplus.co.il

Archive for the ‘cpp’ Category

Imitation of Java Generics

Posted by: rmn on: 31/12/2010

Generic programming is very common and has different names (and features) in various programming languages; C++ provides Turing-Complete Templates, Java offers Generics (along with Ada, Eiffel, C#, and Visual Basic .Net), and Parametric Polymorphism is present in ML, Scala, and Haskell. While I am generally pretty happy with what C++ has to offer, adopting some [...]

Exceptional initialization list

Posted by: rmn on: 30/11/2010

Using the initialization list is very much encouraged in C++, and rightfully so - it has many benefits. But what happens if one of your members fails at initialization and actually throws an exception? Even worse: what happens if that member’s constructor throws an exception not in your exception specification list?

Thunksgiving

Posted by: rmn on: 31/10/2010

Quoting Wikipedia: The word thunk has at least three related meanings in computing science. A “thunk” may be: A piece of code to perform a delayed computation (similar to a closure) A feature of some virtual function table implementations (similar to a wrapper function) A mapping of machine data from one system-specific form to another, [...]

Overloading macros

Posted by: rmn on: 31/08/2010

The feature of function overloading can prove to be pretty useful: it allows us to define a few versions of the same function, which differ in argument types, or even in Arity (ignoring variadic functions for the moment). Unfortunately, the C\C++ pre-processor does not allow overloading macros in the same way; It treats such attempts [...]

Variadic macro to count number of arguments

Posted by: rmn on: 17/07/2010

The C-Preprocessor is a very powerful mechanism, which offers many different features. One of these features is called Variadic macros: macros that accept a varying number of arguments. It is interesting to note at this point, that such Variadic macros, despite being part of the C99 Standard, are not part of the C++ Standard at [...]

Futures: asynchronous invocation

Posted by: rmn on: 31/05/2010

In the concurrent world, a Future object refers to an object whose actual value is to be computed in the future. You can think of it as a handle to an asynchronous invocation of a computation that yields a value. Many so called concurrent programming languages support this idea as a native construct offered by [...]

Quines

Posted by: rmn on: 16/04/2010

A Quine is a computer program which prints a copy of its own source code as its only output. Thus it is theoretically possible to compile such a program, run it, and then have its output compiled again to produce the initial program – in an infinite loop, forever.


Follow

Get every new post delivered to your Inbox.

Join 25 other followers