C++Builder 10.4 Sydney supports the ISO C++17 standard in the Clang based compilers for Win32 and Win64. Part of the C++17 standard includes the Algorithms library that provides execution policies to support parallel operations. Below you will find a simple VCL example that uses the C++ std::vector and the algorithms library sort and parallel execution policy to sort random integers in the vector. This example currently compiles using the Clang base compilers for 32 and 64 bit Windows.
Programming Note: While C++Builder doesn’t officially support the parallel extensions. Some code may compile and execute but it may not be actually parallelizing. A good thing to check is the performance vs single threaded execution.
My VCL form contains a TButton, TLabel and two TMemo components.
The Button on-click event handler contains the simple code to create the vector, sort it and display the results.
#include <algorithm>
If you want to include code for non-Clang and Clang compilers, you can use the following #if, #elif, #else, #endif preprocessor directives in your applications.
C++ 17 References used in this simple example:
std::vector
C++ Containers library std::vector
Defined in header <vector>
https://en.cppreference.com/w/cpp/container/vector
Algorithms library
The algorithms library adds functionality beyond the standard C++ library. This library defines additional functions for searching, sampling, sorting, counting, manipulating, generalized summing and more.
Defined in header <algorithm>
https://en.cppreference.com/w/cpp/algorithm
Sort algorithm
https://en.cppreference.com/w/cpp/algorithm/sort
Algorithm execution policies
https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag
Algorithm execution policy types
https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag_t
Know more about STL’s std::find C++ method to get a hint on how to supercharge your productivity while you write code.