c++ - STL容器相当于Delphi集?

标签 c++ delphi stl

是否有功能类似于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;

最佳答案

最接近 Delphi 的 set of是 STL std::bitset <bitset> 中的容器 header 。

相似点:

  • 您可以在开始时设置它的范围;
  • std::bitset::set等于Include()在德尔福;
  • std::bitset::reset等于Exclude()在德尔福;
  • std::bitset::test()等于in在德尔福;
  • 您可以使用按位运算符(|&<<>>^ 等)。

区别:

  • 在 Delphi 中,a 的最大大小 set是 256 位,所以如果你想创建一个更大的集合,你必须使用类似 array [1..N] of set of byte 的东西.在 C++ 中,std::bitset没有那个限制;
  • 在德尔福中,set位按值包含/排除。在 C++ 中,std::bitset位由索引设置/重置。

关于c++ - STL容器相当于Delphi集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29829961/

相关文章:

c++ - 为什么我的 C++ 程序在将 lambda 转换为函数指针时崩溃

c++ - 为什么std::is_invocable不能与自动推导返回类型的模板化operator()一起使用(例如,通用lambda)

c++ - 显示表单时从 C++ 调用的 Delphi DLL 崩溃

c++ - 在学习 BOOST 替代品之前,我应该精通 STL 库吗?

固定大小 vector 的 C++ vector

c++ - std::tuple 作为类成员

c++ - 初始化派生类的安全方法

c++ - 如何在 VS 2010 Ultimate 中编写和显示 C++ 参数信息?

Delphi 7 : ADO, 需要基本编码示例

delphi - 为什么在 Delphi 2007 IDE 中剪切/粘贴表单组件有时会停止工作?