是否存在功能类似于Delphi"set"的STL容器,以下代码取自DelphiBasics:
type
TDigits = set of '1'..'9'; // Set of numeric digit characters
var
digits : TDigits; // Set variable
myChar : char;
begin
digits := ['2', '4'..'7'];
// Now we can test to see what we have set on:
for myChar := '1' to '9' do
begin
if (myChar In digits) then
DoSomething()
else
DoSomethingElse();
end;
end;
Run Code Online (Sandbox Code Playgroud)
与Delphi最接近的set of是标题中的STL std::bitset容器<bitset>.
相似点:
std::bitset::setInclude()在Delphi中等于;std::bitset::resetExclude()在Delphi中等于;std::bitset::test()in在Delphi中等于;|,&,<<,>>,^,等).区别:
set是256位,所以如果你想创建一个更大的集合,你必须使用类似的东西array [1..N] of set of byte.在C++中,std::bitset没有那个限制;set按值包含/排除位.在C++中,std::bitset通过索引设置/重置位.| 归档时间: |
|
| 查看次数: |
552 次 |
| 最近记录: |