Question: can I have non-const parameters?

1,187 views
Skip to first unread message

Andrew Wolfers

unread,
Aug 2, 2024, 5:26:49 PM8/2/24
to chromi...@chromium.org, Gil Dekel
I have a mojom interface method which accepts an array parameter. The generated C++ converts this to a const vector ref. Is it possible to avoid const?

--

Ken Rockot

unread,
Aug 2, 2024, 5:32:05 PM8/2/24
to Andrew Wolfers, chromi...@chromium.org, Gil Dekel
In general no, but since it's an array of DisplayConfigurationParams, and DisplayConfigurationParams has a C++ type-mapping, you can mark that type as move-only (i.e. set `move_only = True` in the block here), which will cause generated bindings to always pass it by value. This also affects dependent types like array<DisplayConfigurationParams>.

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-mojo/CAJ%2BEePso39vpoWYVJXZG4Cz-f-xjYK%2Bug-X4qNjkSn49EJCD9w%40mail.gmail.com.

Andrew Wolfers

unread,
Aug 2, 2024, 6:35:30 PM8/2/24
to Ken Rockot, chromi...@chromium.org, Gil Dekel
Thank you Ken! I think pass-by-value doesn't work in this case because I do want to mutate the DisplayConfigurationParams. Is it possible to remove const and still pass-by-reference or -by-pointer?

Ken Rockot

unread,
Aug 2, 2024, 6:45:13 PM8/2/24
to chromium-mojo, Andrew Wolfers, chromi...@chromium.org, Gil Dekel, Ken Rockot
On Friday, August 2, 2024 at 3:35:30 PM UTC-7 Andrew Wolfers wrote:
Thank you Ken! I think pass-by-value doesn't work in this case because I do want to mutate the DisplayConfigurationParams. Is it possible to remove const and still pass-by-reference or -by-pointer?

You are free to mutate (or move) the object when it's passed to you by value.
Reply all
Reply to author
Forward
0 new messages