The 25 days of C++mas - December 23 - C++ stack, Lambda expression, Win64/Win32

Posted by on in Blogs
Two more days to go until the 25 days of C++mas are done.  There are two more days until Christmas.  It's raining very hard here in Santa Cruz California (flash flood alerts keep interrupting the San Francisco 49ers vs Seattle Seahawks football game).  I was playing with the C++Builder XE3 64-bit compiler and the support for Lambda Expressions.  I modified an example from our Embarcadero DocWiki that uses a C++ stack and Lambda and updated it to work with both the 32-bit and 64-bit compilers.  In the 64-bit version, unicode strings are pushed onto the stack and a Lambda Expression is used to clear the stack.  In the 32-bit version, unicode strings are pushed onto the stack and a while loop is used to pop the stack until it is empty.

The FireMonkey (FMX) form contains a TButton and a TMemo.

Here is the code containing the Button Click Event Handler:

    #include <fmx.h>
    #pragma hdrstop
    #include "MainUnit.h"
    #include <stack> // from the Dinkumware Standard C++ Library (STL)
    #pragma package(smart_init)
    #pragma resource "*.fmx"
    TForm1 *Form1;
    __fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
    void __fastcall TForm1::Button1Click(TObject *Sender)
    // Create the stack
    std::stack stk; // create stack to contain Unicode Strings
    Memo1->Lines->Add("Stack Created");
    Memo1->Lines->Add("The stack contains: "
    + IntToStr((int)stk.size())
    + " elements.");
    // Add elements to the stack
    Memo1->Lines->Add("Pushed John");
    Memo1->Lines->Add("Pushed Mary");
    Memo1->Lines->Add("Pushed Bob");
    Memo1->Lines->Add("Pushed Anna");
    Memo1->Lines->Add("Pushed Erica");
    // Show the last pushed element "Erica"
    Memo1->Lines->Add("Stack Top element is: " +;
    Memo1->Lines->Add("The stack contains: "
    + IntToStr((int)stk.size())
    + " elements.");
    // Pop the last pushed element
    Memo1->Lines->Add("Popped Stack");
    // Show the number of elements in the stack "4"
    Memo1->Lines->Add("The stack contains: "
    + IntToStr((int)stk.size())
    + " elements.");
    // Show the last pushed element "Anna"
    Memo1->Lines->Add("Top of stack element is: " +;
    #ifdef _WIN64
    // Lambda expression for clearing the stack
    // will work only for 64-bit C++ applications
    () {
    std::stack empty; // create an empty stack
    swap(stk, empty); // swap it with
    Memo1->Lines->Add("Stack Emptied using Lambda Expression");
    // if not Win64 then use loop to empty the stack
    while (!stk.empty()) {
    // Show the number of elements in the stack "0"
    Memo1->Lines->Add("The stack contains: "
    + IntToStr((int)stk.size())
    + " elements.");

The output is the same on 32-bit and 64-bit windows:

Additional information about Lambda Expressions can be found at:

Watch/Download the C++Builder 64-bit Compiler Preview Video

Additional details about the 64-bit C++Builder compiler are available in the preview video.  Watch the C++ 64-bit compiler preview video on YouTube at You can also download the MP4 video file at  The preview video is 9 minutes long.

Try the C++Builder 64-bit compiler

The C++Builder XE3 and RAD Studio XE3 free trial downloads have been updated to include the new C++Builder 64-bit compiler.  Trial downloads are available at

Happy C++mas!

During the first 25 days of December leading up to Christmas, I will blog about the release of the C++Builder 64-bit compiler for Microsoft Windows and C++Builder XE3 support for building VCL and FireMonkey 2 applications.

Gold User, Rank: 1, Points: 2466
David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.


Check out more tips and tricks in this development video: