C++11 containers: move semantic vs pointers

| category: Testing | author: st
Tags: ,

Motivation

C++11 has introduced the move semantic which can also be used in containers instead of "old-school" pointers. The specific containers owning objects has been proposed earlier by third-party libraries like Boost (for example, ptr_map or ptr_vector).

The goal of the test is to compare the speed of manipulations …

C/C++: how to clear a linked circular list

| category: Programming | author: st
Tags: ,

In the case of linked circular list you need to add some checks to avoid memory corruption.

Full example (compiled OK with GCC 8.x)

#include <iostream>
#include <cstdlib>

struct Node
{
    Node(Node* prev, int val)
        : prev(prev), next(NULL), value(val)
    { }
    Node *prev, *next;
    int value;
};

void clear_list(Node …

C/C++: how to clear a linked circular list

| category: Programming | author: st
Tags: ,

In the case of linked circular list you need to add some checks to avoid memory corruption.

Full example (compiled OK with GCC 8.x)

#include <iostream>
#include <cstdlib>

struct Node
{
    Node(Node* prev, int val)
        : prev(prev), next(NULL), value(val)
    { }
    Node *prev, *next;
    int value;
};

void clear_list(Node …

C++Builder: using variant type variable to store Delphi interface

| category: Programming | author: st
Tags: ,

Delphi case

Delphi supports interfaces natively. Any variable of variant type can store an interface like any allowed data types.

program IntfDelphi;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  Classes, SysUtils, Variants;

type
  ITest = interface(IInterface)
    ['{BEDC5E17-2C40-4F7C-8C78-34448F5CE146}']
    procedure Foo(const Msg: string);
  end;

  TestImpl = class(TInterfacedObject, ITest)
  public
    procedure Foo(const Msg …

Using Delphi library with C++ Builder

| category: Programming | author: st
Tags: ,

Since early XE versions C++ Builder supports Delphi units directly added in C++ project and compiles them as well as C/C++ source. However, this approach has several drawbacks:

  • Usually, Delphi files are stored in separated folders of other applications and packages. So your C++ project will point to many …

Happy tickets benchmark

| category: Testing | author: st
Tags: , , ,

Some countries have integer numbers printed on the transport tickets, for example, in ex-USSR. The ticket is "happy" when the sum of the first half of digits equals to the second one. Then you should eat it and make a wish.

Example:

123456 and 111222 are not happy tickets
123123 …

Happy tickets benchmark

| category: Testing | author: st
Tags: , , ,

Some countries have integer numbers printed on the transport tickets, for example, in ex-USSR. The ticket is "happy" when the sum of the first half of digits equals to the second one. Then you should eat it and make a wish.

Example:

123456 and 111222 are not happy tickets
123123 …