6

What's equivalent of std::vector, std::deque and std::map in ObjectPascal (FreePascal compiler)?

In brief:

  • (vector) is an auto-resizing contiguous array

  • (deque) is an auto-sizing hybrid array of arrays giving near O(1) random access while allowing O(1) push/pop from either end

  • (map, unordered_map) is an associative array

Kokizzu
  • 24,974
  • 37
  • 137
  • 233
  • 2
    cheers... I added some tentative explanations that might help Pascal-but-not-C++ programmers help you... tune to taste. – Tony Delroy Mar 18 '15 at 05:53
  • 3
    meanwhile you can examine runtime library source code of classes listed in [wiki.freepascal.org: Data Structures, Containers, Collections](http://wiki.freepascal.org/Data_Structures,_Containers,_Collections) to check if they do what you need – xmojmr Mar 18 '15 at 13:30

1 Answers1

5

In general it is not logical to assume there are direct substitutes in some different language.

Currently FPC generics are a mix of old school C++ like generics (based on token replay), and Delphi more .NET styled generics (fully declarative, but more limited for value types for languages without autoboxing).

Anyway, I'll give it a try:

  1. TList or its generic variants. (TList<> in Delphi or fgl.Tf*List in unit fgl)
  2. No standard type, I have an array of array generic class, but that is optimized to avoid some of the problems of ordered Lists (insertion performance) while still being an ordered type. I've put it on http://www.stack.nl/~marcov/genlight.pas, maybe it gives you some ideas on how to approach the problem.
  3. None yet. TDictionary once http://bugs.freepascal.org/view.php?id=27206 is committed. Currently usually TAVLTree is used.

There is also some generics including a simple deque in packages/fcl-stl, I suggest you check it out.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89