在C ++ Builder 10.4 Sydney for Win32和Win64中使用C ++ 17算法库并行排序

C ++ Builder 10.4 Sydney 在基于Clang的Win32和Win64编译器中支持ISO C ++ 17标准。C ++ 17标准的一部分包括算法库  ,该  库提供执行策略以支持并行操作。在下面,您将找到一个简单的VCL示例,该示例使用C ++ std :: vector以及算法库的sort和parallel执行策略对vector中的随机整数进行排序。本示例当前使用Clang基本编译器针对32和64位Windows进行编译。

我的VCL窗体中包含一个TButton,TLabel和两个TMemo组件。欢迎加入Delphi开发局QQ群:32422310  Delphi控件源码下载网站

C++ Builder 10.4

Button单击事件处理程序包含用于创建向量,对其进行排序并显示结果的简单代码。

#include <algorithm>
#include <vector>

void __fastcall TForm1::Button1Click(TObject *Sender)
{
	const int max_data = 1000;   // number of random numbers to create
	Memo1->Lines->Clear();
	Memo2->Lines->Clear();
	Label1->Caption = "Building Random Data";
	Label1->Update();

	// fill the vector with random numbers and save them in Memo1
	std::vector<int> my_data;

	for (int i = 1; i <= max_data; i++) {
		int random_value = Random(max_data);
		my_data.push_back(random_value);
		Memo1->Lines->Add(IntToStr(random_value));
	}
	Label1->Caption = "Sorting Random Data";
	Label1->Update();

	// sort the random numbers in the vector
	std::sort(std::execution::par,my_data.begin(),my_data.end());

	// put the sorted vector in Memo2
	Label1->Caption = "Sorting Completed";
	Label1->Update();
	for(int n : my_data) {
		Memo2->Lines->Add(IntToStr(n));
	}
}

如果要包括非Clang和Clang编译器的代码,则可以在应用程序中使用以下#if,#elif,#else,#endif预处理程序指令。

#if defined(__clang__)
    #if (__clang_major__ == 5 && __clang_minor__ == 0)
    	#warning "clang major = 5 and clang minor = 0"
    #elif (__clang_major__ == 3 && __clang_minor__ == 3)
    	#warning "clang major = 3 and clang minor = 3"
    #else
    	#warning "Unable to determine correct clang header version"
    #endif
#else
	#warning "not a clang compiler"
#endif

 

 

需要先安装Patch1。 Patch 2 for RAD Studio 10.4 now available This patch addresses a number of issues in RAD Studio 10.4, pertaining to Delphi Compiler, the RAD Studio IDE in general and the new LSP-based Code Insight in particular, plus C++ Builder Android exceptions and some debugger issues. The installation of this patch requires a prior installation of Patch #1 (separately available on GetIt and in the download portal). Installing this patch is recommended for all RAD Studio 10.4 customers. Note that this patch is fairly large to download (around 190 MB). The patch includes detailed installation instructions as part of the Readme. Please read the steps carefully (or the corresponding steps in this blog post), as the GetIt download does not install the patch automatically. You must follow the instructions in order to install. Just using GetIt is not enough. List of Customer Reported Issues Addressed in 10.4 Patch 2 RAD Studio 10.4 Patch #2 addresses the following issues reported by customer on Embarcadero Quality Portal (https://quality.embarcadero.com): RSP-29628 VCL Grids bug RSP-29560 [REGRESSION] Misalignment in TStringGrid, StretchDraw method in OnDrawCell RSP-29412 Compiler generates incorrect code for if-then RSP-29402 Delphi 10.4 TStringGrid.OnDrawCell bug RSP-29374 Wrong rect coords in TStringGridDrawCell, so image are drawn at wrong position RSP-29347 [DelphiLSP] IDE Crashes when view form as text is selected and running LSP server RSP-29310 Internal error L891 when linking because of complex types based on records with class var RSP-29299 CODEGEN bug in managed fields initialization, associated with new management operators. RSP-29271 [DelphiLSP] Code Insight adds unneeded () when changing procedures/functions RSP-29256 Compiler generates wrong code for template function RSP-29227 Incorrect property value obtained from the record RSP-29226 Access violation with working code under 10.2 RSP-29218 compiling static library under Android error E4620 processing resource .fmx -2 raised RSP-29172 Access Violation when opening License Manager RSP-29142 GoTo statements not working RSP-29136 Dialog constantly pops up during debugging RSP-29129 iOS App simply crashes with a TWebBrowser on it. RSP-29127 Compiler internal error if you ignore the result of a function that returns a generic record RSP-29124 ICE E1812 RSP-28989 License Manager has access violation error when i click on Workstation Licenses RSP-28887 Space does not finish code completion RSP-28857 Default(T) generates bad code for managed record RSP-28821 [Regression] TStringGrid.OnDrawCell parameter Rect contains wrong values RSP-28808 Project options dialog page "Delphi Compiler" is not populated when opening the dialog RSP-28796 RVO for M-records: initialisation of local variables RSP-28761 [REGRESSION] E2154 Type 'T' needs finalization - not allowed in variant record RSP-28737 Compiler error when inlining new Bit Counting Standard Functions RSP-28735 Managed Records Causing Internal Compiler Error RSP-28717 Delphi Package fails to compile RSP-28701 Bind visually on TDBGRID kills the IDE RSP-28669 [BadCG] Value M-record parameters: improper AddRefRecord RSP-28659 RVO for M-records: assignment to local variables RSP-28616 [BadCG] Operator Assign should not allow non-default calling conventions RSP-28615 [BadCG] In the absence of Initialize, finalisation is not guaranteed for local variables RSP-28552 Poor code generation for local managed record variables RSP-28499 Options - Translation tools - Font - Corrupted? RSP-28476 LSP ErrorInsight in Structure Pane only shows one keystroke after editor RSP-28400 [BadCG] Operator Assign is not always invoked for fields RSP-28372 [Regression] Bad codegen in function returning generic type RSP-27268 C++ Builder 10.3.3 Android Exceptions RSP-27251 Internal error when trying to inline with optimization on RSP-24079 Package version is broken RSP-23403 Build for linux 64 error RSP-23024 Record helper class constructor gives senseless compiler warning RSP-22318 Pointer type check missed when object field is a dynarray RSP-21554 Compiler generates incorrect code for parameterized record type RSP-21248 Const dynamic array unexpectedly contains uninitialized data RSP-20372 A generic "reference to function" will only match the first of several overloaded functions RSP-19714 Win32 compiler - Memory corruption with array helpers RSP-18241 *.c source files, added to C++ project, got added to DeploymentManager file list RSP-18148 AV in TList.Remove (64-bit compiler only)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值