<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 20 Jul 2022 at 09:15, Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.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">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 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 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></blockquote><div><br></div><div>Bonus marks if somebody could explain to me why I need to cast entry->second to a const for get() to work...?  If I don't, the following statement:</div><div><br></div><div>return entry->second.get<T>()</div><div><br></div><div>returns the following compile error:</div><div><br></div><div>../include/libcamera/controls.h: In member function ‘std::optional<_Tp> libcamera::ControlList::get(const libcamera::Control<T>&) const’:<br>../include/libcamera/controls.h:384:33: error: expected primary-expression before ‘>’ token<br>  384 |   return ((entry->second)).get<T>();<br>      |                                 ^<br>../include/libcamera/controls.h:384:35: error: expected primary-expression before ‘)’ token<br>  384 |   return ((entry->second)).get<T>();<br></div><div><br></div><div>?</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>
        template<typename T, typename V><br>
-- <br>
2.25.1<br>
<br>
</blockquote></div></div>