GSRoot and STL analogies

This document contains the analogies between GRAPHISOFT’s GSRoot and STL entities.

GS::Array ~ std::vector

GS::Array<int> arr;
arr.Push (5);
arr.Push (6);
int sum = 0;
for (UIndex i = 0; i < arr.GetSize (); ++i) {
    sum += arr[i];
}
assert (sum == 11);
std::vector<int> arr;
arr.push_back (5);
arr.push_back (6);
int sum = 0;
for (UIndex i = 0; i < arr.size (); ++i) {
    sum += arr[i];
}
assert (sum == 11);

GS::Array ~ std::stack

GS::Array<int> stack;
stack.Push (5);
stack.Push (6);
int sum = 0;
while (!stack.IsEmpty ()) {
    sum += stack.GetLast ();
    stack.Pop ();
}
assert (sum == 11);
std::stack<int> stack;
stack.push (5);
stack.push (6);
int sum = 0;
while (!stack.empty ()) {
    sum += stack.top ();
    stack.pop ();
}
assert (sum == 11);

GS::Queue ~ std::queue

GS::Queue<Int32> queue;
queue.Push (5);
queue.Push (6);
Int32 sum = 0;
while (!queue.IsEmpty ()) {
    sum += queue.Peek ();
    queue.Pop ();
}
assert (sum == 11);
std::queue<int> queue;
queue.push (5);
queue.push (6);
int sum = 0;
while (!queue.empty ()) {
    sum += queue.front ();
    queue.pop ();
}
assert (sum == 11);

GS::FixArray ~ std::array

GS::FixArray<int, 2> arr;
arr[0] = 5;
arr[1] = 6;
assert (arr.GetSize () == 2);
std::array<int, 2> arr;
arr[0] = 5;
arr[0] = 6;
assert (arr.size () == 2);

GS::Ref ~ std::shared_ptr

GS::Ref<A> ptr (new A ());
GS::Ref<A> ptr2 = ptr;
assert (ptr == ptr2);
assert (*ptr == *ptr2);
assert (ptr->Func () == 5);
std::shared_ptr<A> ptr (new A ());
std::shared_ptr<A> ptr2 = ptr;
assert (ptr == ptr2);
assert (*ptr == *ptr2);
assert (ptr->Func () == 5);

GS::Pair ~ std::pair

GS::Pair<int, int> pair (5, 6);
assert (pair.first == 5);
assert (pair.second == 6);
std::pair<int, int> pair (5, 6);
assert (pair.first == 5);
assert (pair.second == 6);

GS::HashTable ~ std::unordered_map

GS::HashTable<int, int> hashTable;
hashTable.Add (5, 6);
assert (hashTable.ContainsKey (5));
assert (hashTable[5] == 6);
std::unordered_map<int, int> hashTable;
hashTable.insert (std::pair<int, int> (5, 6));
assert (hashTable.find (5) != hashTable.end ());
assert (hashTable[5] == 6);

GS::HashSet ~ std::unordered_set

GS::HashSet<int> hashSet;
hashSet.Add (5);
assert (hashSet.Contains (5));
std::unordered_set<int> hashSet;
hashSet.insert (5);
assert (hashSet.find (5) != hashSet.end ());