Container STL equivalent for Delphi?

Is there an STL container with functionality like Delphi "set", the code below is taken from 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;

      

+3


source to share


1 answer


The closest Delphi equivalent set of

is the STL container std::bitset

in the header <bitset>

.

Similarities:

  • You can set its range at the beginning;
  • std::bitset::set

    in Delphi is Include()

    ;
  • std::bitset::reset

    equal Exclude()

    in Delphi;
  • std::bitset::test()

    in Delphi is in

    ;
  • You can use the bitwise operators ( |

    , &

    , <<

    , >>

    , ^

    , etc.).


Differences:

  • In Delphi, the maximum size set

    is 256 bits, so if you want to create a large set you should use something like array [1..N] of set of byte

    . C ++ std::bitset

    doesn't have this limitation;
  • In Delphi, bits are set

    included / excluded by value. In C ++, bits std::bitset

    are set / reset by index.
+7


source







All Articles