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

This topic is 797 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites

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

I'll look into this.

##### Share on other sites

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.

##### Share on other sites

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!

##### Share on other sites

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.

Edited by Andreas Jonsson

##### Share on other sites

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?

##### Share on other sites

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.

##### Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632912
• Total Posts
3009186
• ### Who's Online (See full list)

There are no registered users currently online

×