[libcamera-devel] [PATCH 01/11] Fixes Bug 156, which breaks libcamera on Android < 12.

Naushir Patuck naush at raspberrypi.com
Wed Oct 26 10:46:51 CEST 2022


Hi,

On Wed, 26 Oct 2022 at 09:24, Kieran Bingham via libcamera-devel <
libcamera-devel at lists.libcamera.org> wrote:

> Quoting Nicholas Roth (2022-10-26 02:50:34)
> > Another possible fix is to cast libcamera::utils::Duration to
> > std::chrono::duration before performing division. I've tested that and it
> > works. Would folks be amenable to that instead?
>
> That sounds like we still have to make global updates. Are any of those
> locations where we should store a libcamera::utils::Duration instead of
> a std::chrono::duration to prevent having to cast?
>
> If casting works around the issue, is it sufficient / possible to
> provide an explicit casting operator? (I've never done this to more than
> the POD types, but it 'looks' like you can specify specific target
> classes as an operator?)
>
>   https://en.cppreference.com/w/cpp/language/cast_operator


Casting like this is indeed possible, but even then, the changes required
are spread across the codebase.  IMO this is undesirable for readability,
and error prone as any future developers must know to do this cast
if they were to do computations with utils::Duration.

I hope there is a centralized solution with operator / overloading, but
if there's no choice...

Naush


>
> Something like (I have no idea if this is something that can work, or if
> it helps the compiler as it should already know the type?!)...:
>
> class Duration : public std::chrono::duration<double, std::nano>
> {
> ...
>
>         explicit operator std::chrono::duration() {
>                 return std::chrono::duration_cast<BaseDuration>>(*this);
>         }
>
> or perhaps 'worse' ? (but at least isolated to here in the class?)...
>
>         constexpr explicit operator double() {
>                 return get<std::nano>();
>         }
>
> ...
> }
>
> --
> Kieran
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20221026/b89dad5a/attachment.htm>


More information about the libcamera-devel mailing list