From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D569BC433DF for ; Tue, 20 Oct 2020 05:57:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F0722225F for ; Tue, 20 Oct 2020 05:57:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=intenta.de header.i=@intenta.de header.b="u4u6lCgE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730606AbgJTF5W (ORCPT ); Tue, 20 Oct 2020 01:57:22 -0400 Received: from mail.intenta.de ([178.249.25.132]:41116 "EHLO mail.intenta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730544AbgJTF5W (ORCPT ); Tue, 20 Oct 2020 01:57:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=intenta.de; s=dkim1; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:CC:To:From:Date; bh=DxkOG6tcL5gcKVIp0/e9Zt2RcQOYn4aTzs2TtB6IKY4=; b=u4u6lCgEclOBj535R4RCX01d1BQS9zVS90ykRgZGIlVmZ9CZ64R2s5eQ/MqpTISj+NNUhKyTZK5VC9aGDQ/DxK0ooDW1a2QpA+fUZwqD5ZlHpqRr02wf+uhlNUMZk5jNKZCqvLn/IZEKhxAtSj6Nkj3jZpZo0lxZjedPyFcew88Ns3H6gRbpJbVY2tdu6fumz5L3Fx/tAltOGjUOQAqmPR7sQg2dtdQufOtoNgf0A1Ht+hh8cYcGXNJcJ8ZxGuU7Hus8ai/1ow8nKRsVCkc7xqMv2EVnlEcICglEIxKc5zNvhCX/SMRwfogzwPumJHzPMfcbDYP8MP1aXQ6ApcVNoA==; Date: Tue, 20 Oct 2020 07:57:14 +0200 From: Helmut Grohne To: Bartosz Golaszewski CC: Bartosz Golaszewski , Kent Gibson , "linux-gpio@vger.kernel.org" Subject: Re: [libgpiod][RFC PATCH] bindings: cxx: demote the line's parent chip reference to a weak_ptr Message-ID: <20201020055714.GA10256@laureti-dev> References: <20201016090949.24456-1-brgl@bgdev.pl> <20201016102937.GA22245@laureti-dev> <20201019123801.GA5116@laureti-dev> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-ClientProxiedBy: ICSMA002.intenta.de (10.10.16.48) To ICSMA002.intenta.de (10.10.16.48) Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On Mon, Oct 19, 2020 at 03:06:18PM +0200, Bartosz Golaszewski wrote: > But this still forces us to do > > return chip(::std::shared_ptr<::gpiod_chip>(this->_m_owner)); > > instead of a much more elegant > > return chip(this->_m_owner); > > in line.cpp and there's an even less elegant thing in iter.cpp. Or am > I missing something? I confirm the behaviour you see. My intuition that the conversion would happen implicitly was wrong. Still the sticking point is this: Your constructor should allow for most flexibility to the caller and in this case that means it should consume a shared_ptr by value. In order to make the case with a weak_ptr bearable, I suggest adding a delegating constructor: chip(const ::std::weak_ptr<::gpiod_chip>& chip_ptr) : chip(::std::shared_ptr<::gpiod_chip>(chip_ptr)) {} That way your desired way of calling should continue to work while not forcing callers to convert a real shared_ptr to weak_ptr and back. Sorry for the confusion about this. Helmut