Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced container operations #1622

Open
deadlocklogic opened this issue Aug 12, 2024 · 0 comments
Open

Enhanced container operations #1622

deadlocklogic opened this issue Aug 12, 2024 · 0 comments

Comments

@deadlocklogic
Copy link
Contributor

Sometimes a container type may have missing semantics in order to be customized as in containers.
For example:

  • a sequence container type missing max_size() will fail to compile.
    for (lua_Integer i = 0;; i += lua_size<V>::value, lua_pop(L, lua_size<V>::value)) {
    if (idx >= cont.max_size()) {
    // see above comment
    goto done;
  • a sequence container type missing value_type will fail to compile.
    typedef typename Tu::value_type V;
    unqualified_getter<as_table_t<T>> g {};
    return g.get(types<nested<V>>(), L, index, tracking);

Here is a concrete example (actually I encountered a similar case in a library: the containers in the skia library SkSpan, TArray, STArray):

template <typename T>
class Vector
{
private:
    std::vector<T> data; // changed to map

public:
    // Intentionally omitted
    // using value_type = typename std::vector<T>::value_type;
    using iterator = typename std::vector<T>::iterator;
    using size_type = typename std::vector<T>::size_type;
    using reference = typename std::vector<T>::reference;

    iterator begin()
    {
        return iterator(data.begin());
    }
    iterator end()
    {
        return iterator(data.end());
    }
    reference operator[](size_type n)
    {
        return data[n];
    }
};

I suggest deferring such missing traits in the container type to the customization traits sol::usertype_container.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant