Improbable Icon

Map\list quick suggestion

unreal
v12-0-4

#1

Would be great to have basic functionality for spatial types provided by codegen
List

  • remove index from array (removes specified index in array)
  • override list value by key is missing

Map

  • length of a map (returns int length)
  • keys of a map (rerturns all keys)
  • override value by key

those list\maps vars are strange without them


#3

Thanks for your feedback @swdan90! I’ll move this to the feedback section, as it fits better it there; hope you don’t mind.


#4

Just a little update on this: to get length of a map, you can use size() method, and to erase a particular element of a list, you can do list.erase(list.begin() + i). To get keys of a map, you’ll have to iterate over it. Hope this helps.


#5

sure. however there are no built in (could not find em? o_O) functions. implementing by myself returned funny results. got workaround for now, but would be nice to have them in in the future.


#6

Sorry for the delay @swdan90! And sorry if I’m misunderstanding your question, but there is a built in function for removing a list element (worker::List::erase()) and one for obtaining the length of a map (worker::Map<T, T>::size()). Is that what you were looking for?


#7

yes. this one. wasted like week, still can’t get it working.


#8

Would this help?

template <class T>
void remove(worker::List<T>& list, const T& item)
{
    list.erase(std::remove(list.begin(), list.end(), item), list.end());
}

template <class T>
void remove_at(worker::List<T>& list, const size_t index)
{
    list.erase(list.begin() + index);
}

template <class T>
void print(const worker::List<T>& list)
{
    std::cout << "size: " << list.size() << std::endl;

    for (const auto& value : list)
    {
        std::cout << value << std::endl;
    }
}

// Entry point
int main(int argc, char** argv) {
    worker::List<int> list;
    list.emplace_back(12);
    list.emplace_back(25);
    list.emplace_back(9);
    list.emplace_back(25);
    list.emplace_back(100);

    remove_at(list, 2);
    remove(list, 25);
    print(list);

    worker::Map<std::string, int> map;
    map["a"] = 0;
    map["b"] = 2;
    map["c"] = 4;

    worker::List<std::string> keys;
    for (const auto& value : map)
    {
        keys.emplace_back(value.first);
    }

    remove<std::string>(keys, "a");
    print(keys);
}

#9

yep, thanks. tho i solved this in similar manner before saw your post.

also in the map. Emplace fails if key exists and there is no function that can modify value by key.
created my own :\

requesting this one as well


#10

also override list value by key is missing