Advertisement

Problem In Array::find With A 'const' Param

Started by August 03, 2016 04:28 PM
6 comments, last by IronHawk 8 years, 3 months ago

Hello!

I'm getting a compile error on searching for an item index in the array when I pass the const value to find().

For example it's impossible to compile class like this:


class CDataHolder {
    private array<CData@> m_arr;

    int32 getIndex(const CData@ hData) const {
        return m_arr.find(@hData);  // <<<<<<< Compile error
    }

    ...
}

The error message is: No matching signatures to 'array::find(const CData@&) const'

But in add-on the find() function is registered as:


... RegisterObjectMethod("array<T>", "int find(const T&in value) const" ...

So it must work with const parameters too. Or I'm wrong with this?

Thanks in advance!

Looks like you may have come across a bug in the compiler.

I'll look into this.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

Hmm. It's not actually a bug. It's a restriction imposed by the language.

You see, the signature "int find(const T&in value) const" registered by the array template, is expanded to "int find(CData@ const &in) const" and not "int find(const CData@&in) const".

"CData@ const" means that the handle is const (i.e. cannot be reassigned to a different object), but the object it refers to is not const.

This is why the find method doesn't match when you pass a "const CData@" to the function. A handle to a const object cannot be passed to a function that expects a handle to a non-const object.

I'll need to think of a way to allow the application to inform when "const T&in" should be expanded to "CData@ const &in" or "const CData@ const &in" so that this situation can be resolved. This will most likely require quite a few changes in the library, so it will take a while.

In the mean time, try to see if you can avoid using const CData.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Hello, Andreas!

Thank you very much for such a detailed description.

Yes, now I just removed the const and marked the place in code as "required refactoring in future".

That would be good of course to have solution from you.

Thanks!

Well, well. I had clearly overestimated the difficulty of adding this support. Once I identified the path I wanted to go it took no more than a couple of hours to have it working.

Give revision 2343 a try. It should solve your issue.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Hello, Andreas!

I updated AS version to "2.31.2 WIP".

And with const all now works properly.

Thank you!

Only the JIT compiler crashes on module->Build().

Can it be that JIT has some incompatibilities with current AS version?

Advertisement

According to the JIT github page it is compatible with version 2.31.0 of AngelScript. None of the changes that I've done in 2.31.1 or 2.31.2 WIP should break that compatibility as far as I'm aware of.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

None of the changes that I've done in 2.31.1 or 2.31.2 WIP should break that compatibility as far as I'm aware of.

OK. Thank you.

This topic is closed to new replies.

Advertisement