Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of C++ std::vector, std::deque and std::map in FreePascal

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

like image 217
Kokizzu Avatar asked Mar 18 '15 05:03

Kokizzu


1 Answers

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.

like image 83
Marco van de Voort Avatar answered Sep 27 '22 19:09

Marco van de Voort