serenity icon indicating copy to clipboard operation
serenity copied to clipboard

AK: Difference in const-ness doesn't compile when used in iterators

Open shannonbooth opened this issue 1 year ago • 3 comments

The following snippets don't compile with AK::Vector, but do using std:: equivalents.

    const int* object = nullptr;
    Vector<int*> vector;
    auto it = vector.find(object);

And in web land:

    JS::GCPtr<JS::Object const> object;
    Vector<JS::GCPtr<JS::Object>> vector;

    auto it = vector.find(object)

etc. for all iterators

It would be nice if these could compile to avoid messiness with casting of const.

shannonbooth avatar Apr 01 '24 14:04 shannonbooth

Looks like const int* cannot be bind to int* const&

bfjm avatar Apr 08 '24 14:04 bfjm

std::vector has no find function, only algorithm has std::find

bfjm avatar Apr 09 '24 14:04 bfjm

Yup, but I mean the equivalent way of writing this in std. To give a more clear example then, here's a serenity version that doesn't compile:

    int* y = nullptr;
    Vector<int const*> vector;

    auto it = find(vector.begin(), vector.end(), y);

And equivalent std:: version that does compile.

    int* y = nullptr;
    std::vector<int const*> vector;

    auto it = std::find(vector.begin(), vector.end(), y);

shannonbooth avatar Apr 09 '24 14:04 shannonbooth