[{"id":13465,"web_url":"https://patchwork.libcamera.org/comment/13465/","msgid":"<20201024163312.7e4yc6nmwvznvwbw@uno.localdomain>","date":"2020-10-24T16:33:12","subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: Disable\n\tControlValue<T> construction from unsupported T","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Sat, Oct 24, 2020 at 01:00:20AM +0300, Laurent Pinchart wrote:\n> The ControlValue<T> constructor for non-array values is a template\n> function that participates in overload resolution for all T types that\n> are not Span or std::string. Other T types that are not supported then\n> result in a compilation error.\n>\n> This causes issues when calling an overloaded function that can accept\n> both a ControlValue and a Span with an std::array<U> parameter. The\n> first overload will be resolved using implicit construction of a\n> ControlValue from the std::array<U>, while the second overload will be\n> resolved using implicit construction of a Span<U> from the\n> std::array<U>. This results in a compilation error due to an ambiguous\n> function call.\n>\n> The first overload is invalid, selecting it would result in a\n> compilation error in the ControlValue constructor, as the\n> ControlValue<T> constructor doesn't support std::array<U> for type T.\n> The compiler can't know about that, as overload resolution happens\n> earlier.\n\nmind->bend();\n\n:)\n\n>\n> To fix it, we can disable the ControlValue<T> constructor for\n> unsupported types T, moving the type check from compilation of the\n> function to overload resolution. The constructor will not participate in\n> overload resolution, and the call won't be ambiguous. The end result is\n> the same for unsupported types, compilation will fail.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nThanks, this should solve the issue I had with ControlInfo()\nconstructor that took a Span<ControlValue>\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n> ---\n>  include/libcamera/controls.h | 1 +\n>  1 file changed, 1 insertion(+)\n>\n> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\n> index 3d7f4b0dc1a7..3b7f3347761e 100644\n> --- a/include/libcamera/controls.h\n> +++ b/include/libcamera/controls.h\n> @@ -97,6 +97,7 @@ public:\n>\n>  #ifndef __DOXYGEN__\n>  \ttemplate<typename T, typename std::enable_if_t<!details::is_span<T>::value &&\n> +\t\t\t\t\t\t       details::control_type<T>::value &&\n>  \t\t\t\t\t\t       !std::is_same<std::string, std::remove_cv_t<T>>::value,\n>  \t\t\t\t\t\t       std::nullptr_t> = nullptr>\n>  \tControlValue(const T &value)\n> --\n> Regards,\n>\n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 038EFC3B5C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 24 Oct 2020 16:33:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 77BE661D64;\n\tSat, 24 Oct 2020 18:33:15 +0200 (CEST)","from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A786C605BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 24 Oct 2020 18:33:14 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 0887F60004;\n\tSat, 24 Oct 2020 16:33:13 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Sat, 24 Oct 2020 18:33:12 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20201024163312.7e4yc6nmwvznvwbw@uno.localdomain>","References":"<20201023220020.22536-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201023220020.22536-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: Disable\n\tControlValue<T> construction from unsupported T","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]