<div dir="ltr"><div dir="ltr">Hi Laurent,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 20 Jul 2022 at 11:19, Laurent Pinchart <<a href="mailto:laurent.pinchart@ideasonboard.com">laurent.pinchart@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Naush,<br>
<br>
On Wed, Jul 20, 2022 at 09:17:45AM +0100, Naushir Patuck via libcamera-devel wrote:<br>
> On Wed, 20 Jul 2022 at 09:15, Naushir Patuck wrote:<br>
> <br>
> > Now that ControlList::get() returns a std::optional<T> to handle missing<br>
> > controls, the error log message in the call to ControlList::find() is<br>
> > unnecessary and likely invalid.<br>
> ><br>
> > Fix this by avoding the call to ControlList::find() from<br>
> > ControlList::get() and<br>
> > replacing with a call to the underlying std::unordered_map::find().<br>
> ><br>
> > Fixes: 1c4d48018505 ("libcamera: controls: Use std::optional to handle<br>
> > invalid control values")<br>
> > Signed-off-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank">naush@raspberrypi.com</a>><br>
> > ---<br>
> > include/libcamera/controls.h | 7 ++++---<br>
> > 1 file changed, 4 insertions(+), 3 deletions(-)<br>
> ><br>
> > diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h<br>
> > index 192be78434dc..8362fce813fb 100644<br>
> > --- a/include/libcamera/controls.h<br>
> > +++ b/include/libcamera/controls.h<br>
> > @@ -376,11 +376,12 @@ public:<br>
> > template<typename T><br>
> > std::optional<T> get(const Control<T> &ctrl) const<br>
> > {<br>
> > - const ControlValue *val = find(<a href="http://ctrl.id" rel="noreferrer" target="_blank">ctrl.id</a>());<br>
> > - if (!val)<br>
> > + const auto entry = controls_.find(<a href="http://ctrl.id" rel="noreferrer" target="_blank">ctrl.id</a>());<br>
> > + if (entry == controls_.end())<br>
> > return std::nullopt;<br>
> ><br>
> > - return val->get<T>();<br>
> > + const ControlValue &val = entry->second;<br>
> > + return val.get<T>();<br>
> <br>
> Bonus marks if somebody could explain to me why I need to cast<br>
> entry->second to a const for get() to work...? If I don't, the following<br>
> statement:<br>
> <br>
> return entry->second.get<T>()<br>
> <br>
> returns the following compile error:<br>
> <br>
> ../include/libcamera/controls.h: In member function ‘std::optional<_Tp><br>
> libcamera::ControlList::get(const libcamera::Control<T>&) const’:<br>
> ../include/libcamera/controls.h:384:33: error: expected primary-expression<br>
> before ‘>’ token<br>
> 384 | return ((entry->second)).get<T>();<br>
> | ^<br>
> ../include/libcamera/controls.h:384:35: error: expected primary-expression<br>
> before ‘)’ token<br>
> 384 | return ((entry->second)).get<T>();<br>
> <br>
> ?<br>
<br>
You need to write<br>
<br>
return entry->second.template get<T>();<br>
<br>
Quoting the C++ standard,<br>
<br>
When the name of a member template specialization appears after . or -><br>
in a postfix-expression, or after nested-name-specifier in a<br>
qualified-id, and the postfix-expression or qualified-id explicitly<br>
depends on a template-parameter (14.6.2), the member template name must<br>
be prefixed by the keyword template. Otherwise the name is assumed to<br>
name a non-template.<br>
<br>
The "The template disambiguator for dependent names" section in<br>
<a href="https://en.cppreference.com/w/cpp/language/dependent_name" rel="noreferrer" target="_blank">https://en.cppreference.com/w/cpp/language/dependent_name</a> is easier to<br>
understand for us humans (I didn't say easy though).<br></blockquote><div><br></div><div>Wow, I would have never ever guessed that as a solution :-)</div><div><br></div><div>Naush</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> > }<br>
> ><br>
> > template<typename T, typename V><br>
<br>
-- <br>
Regards,<br>
<br>
Laurent Pinchart<br>
</blockquote></div></div>