<div dir="ltr"><div dir="ltr">Hi,<div><br></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 26 Oct 2022 at 09:24, Kieran Bingham via libcamera-devel <<a href="mailto:libcamera-devel@lists.libcamera.org">libcamera-devel@lists.libcamera.org</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">Quoting Nicholas Roth (2022-10-26 02:50:34)<br>
> Another possible fix is to cast libcamera::utils::Duration to<br>
> std::chrono::duration before performing division. I've tested that and it<br>
> works. Would folks be amenable to that instead?<br>
<br>
That sounds like we still have to make global updates. Are any of those<br>
locations where we should store a libcamera::utils::Duration instead of<br>
a std::chrono::duration to prevent having to cast?<br>
<br>
If casting works around the issue, is it sufficient / possible to<br>
provide an explicit casting operator? (I've never done this to more than<br>
the POD types, but it 'looks' like you can specify specific target<br>
classes as an operator?)<br>
<br>
  <a href="https://en.cppreference.com/w/cpp/language/cast_operator" rel="noreferrer" target="_blank">https://en.cppreference.com/w/cpp/language/cast_operator</a></blockquote><div><br></div><div>Casting like this is indeed possible, but even then, the changes required</div><div>are spread across the codebase.  IMO this is undesirable for readability,</div><div>and error prone as any future developers must know to do this cast</div><div>if they were to do computations with utils::Duration.</div><div><br></div><div>I hope there is a centralized solution with operator / overloading, but</div><div>if there's no choice...</div><div><br></div><div>Naush</div><div><br></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>
Something like (I have no idea if this is something that can work, or if<br>
it helps the compiler as it should already know the type?!)...:<br>
<br>
class Duration : public std::chrono::duration<double, std::nano><br>
{<br>
...<br>
<br>
        explicit operator std::chrono::duration() {<br>
                return std::chrono::duration_cast<BaseDuration>>(*this);<br>
        }<br>
<br>
or perhaps 'worse' ? (but at least isolated to here in the class?)...<br>
<br>
        constexpr explicit operator double() {<br>
                return get<std::nano>();<br>
        }<br>
<br>
...<br>
}<br>
<br>
--<br>
Kieran<br>
</blockquote></div></div>