220 40780 <2314717.GH8Ag49nql@tjmaciei-mobl1> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: a string type for APIs
Date: Fri, 26 Oct 2018 10:59:05 -0700
Lines: 74
Approved: news@gmane.org
Message-ID: <2314717.GH8Ag49nql@tjmaciei-mobl1>
References: <CAF9gR9e5Kfy+TBtkRf-2i8EQ42Q5eRTQc0P9HLu9PP9UG4RCjg@mail.gmail.com> <13400688.pJn7XIzHAo@tjmaciei-mobl1> <CAF9gR9eYfBmL7rtc+uZ6L0q2jkQCPiJenwmfWGsDz4oBSx+yFw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: blaine.gmane.org 1540576628 9983 195.159.176.226 (26 Oct 2018 17:57:08 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 26 Oct 2018 17:57:08 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRB4NLZXPAKGQEV2AW3GI@isocpp.org Fri Oct 26 19:57:04 2018
Return-path: <std-proposals+bncBCB4TK757YBRB4NLZXPAKGQEV2AW3GI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qt1-f200.google.com ([209.85.160.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB4TK757YBRB4NLZXPAKGQEV2AW3GI@isocpp.org>)
	id 1gG6M4-0002UW-0j
	for gclcip-std-proposals@m.gmane.org; Fri, 26 Oct 2018 19:57:04 +0200
Original-Received: by mail-qt1-f200.google.com with SMTP id x18-v6sf1876500qts.11
        for <gclcip-std-proposals@m.gmane.org>; Fri, 26 Oct 2018 10:59:14 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1540576754; cv=pass;
        d=google.com; s=arc-20160816;
        b=Q93wdfbW/UAGcNfbaOecMldXcyEApGeTMfTHXD3cCfXlOQYzySULDmxKjXQnpcYm1k
         moJE7Fvw/NTsKsgYjbzfT+L6Jj/Xyjr4JFcVq03uz9b73bAxLDO2cLtfbovM8CNRksrZ
         o6V9m3qx6Wyr458bLpVnGGbCd9IU4SVcuMYcg0d+CCwkPypIi6tUW7xeli+YMkyspm1X
         DzwOZZmGPapsx+FfbxaVLuYlDsgN8LDXJLV34Ee4PB7NDExZJdd3ZaedA9N5CuB4iAVi
         j7nhC1fBlf/o86l+0NcJUov7NsTGZQveNwPQjaBTOxzLdA2SYbtnYyoXi7XomPLg9p4q
         SC9g==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:mime-version:references
         :in-reply-to:message-id:date:subject:to:from:dkim-signature;
        bh=2FCSQptinebp0M3VKxycVYlVxmMxZLnj/h/lEtJLGF0=;
        b=Jmh//mxrlveJCY8Lq8cjva1or9DnvPiOql2r+HG57yAbdcBtHmfJXmuw1GzpD0N55S
         kW8jyWAdgzbG3gJUMFtCXinRMxa8DCdjbr1EvoNRVzi1NnWowIJbukVk8R1uZLNPHUIu
         PvH7flnVmaq0I2LFTcdXSqyuiozFiwdk0nohL/xjnv6iECfSQNBxR1m0JB2dhLbktXVy
         3L8Qf+RlYdIf/pNdZ0cYQ2LWshGikCkjO+LUGM6DugAWAYdokyHwde2A69zr5Z+aZ5Ik
         V+mjuiQoh7EsJkCq7z9QhNtSSkt2HKVxwYavdafG8t1t8/MVsF+09tnXKMFBGnsUaFoO
         P+iQ==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 209.222.10.136 as permitted sender) smtp.mailfrom=thiago@macieira.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:to:subject:date:message-id:in-reply-to:references:mime-version
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=2FCSQptinebp0M3VKxycVYlVxmMxZLnj/h/lEtJLGF0=;
        b=CgYFxJPrs7O8uSrLxRekv+hxfGXRRgj8i65pzVCXPGvBZe4gS4SW0chiC+wm2wWiPS
         6HUCFR6qZmPbeNU+FTBJR37qg8J91WH7ngHu8O2WzoCmIkSsuxkFLCTxwu/xsReZOFNd
         j/rrtw5+AXhlrcuWwPKzxgFXcbR9DUFXvM5kEKIpVo37NQjShCfz0rJGIS+Wiq/kE1Zw
         qC2U+wHRr/VZT2enUT73/Rf731zlcMF/kouZ1BRa/75ikETEFsmy+lKDUqvGvaDq49yk
         2o0Hv1IDmnsYJyKEpzIJXFB1BVK0tcbiNxCI8GQkue5cNTgjweHaSWIxNYL0TrQLCkX5
         8DiQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references:mime-version:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=2FCSQptinebp0M3VKxycVYlVxmMxZLnj/h/lEtJLGF0=;
        b=BpDmrgrGPaMUFV2sQ27wa5opuMdMxxXTDcoxo0XAQZVJBp3UApjnPvR5k2cOquK21P
         crjVNr5TTvoM5+DtviRcuJLVSDZxOU+/+m6fQvb178rx4NmT2eZoz6ojv/kPQRnDd0ot
         JL+DSKTy4eKwboVmTNJdday2aJ6TatYjs/L2VuWcd7PgfLI8csETZskPFA3xi6Q8Yx+8
         43IbD+m3+h4owwi0koqFugX5v8R7gnHbM5ggSTZaT23N4AjEhLxOrf5wYcp5j9OLKqYK
         +qnLygwIS8Gk+dIPT7Oruaf5aDn1Hgtt8JpGPmp0GXrzFNPKgoT9p/DvoTaLJxZ+DQQI
         WRvw==
X-Gm-Message-State: AGRZ1gKup0ydAD+dhpt9Zb/l20fPAtqTwTsNx7zFD4kQhdgC1yeRqCLt
	0/11R/5r1q2IwV441vhabT7jAg==
X-Google-Smtp-Source: AJdET5cgbLqSAPM06U8xHps4Vj5SJkGeRyMXi+Ke0n9cmQZ+NPXCnIcM47c5SmeDj6SZeIXXLxZgEA==
X-Received: by 2002:a37:5108:: with SMTP id f8-v6mr3782569qkb.54.1540576754344;
        Fri, 26 Oct 2018 10:59:14 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:ac8:251a:: with SMTP id 26-v6ls1034328qtm.10.gmail; Fri, 26
 Oct 2018 10:59:13 -0700 (PDT)
X-Received: by 2002:aed:34a6:: with SMTP id x35-v6mr3850760qtd.93.1540576753064;
        Fri, 26 Oct 2018 10:59:13 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1540576753; cv=none;
        d=google.com; s=arc-20160816;
        b=aFFU/GASGJwRokO9jL3XM7IOc3C4JxmYGMPkPlnRHVeVQPZ3zVMyrszZ4dbSHaf5sb
         5ETrwCRWjx4+rxGFzH3xWZCOSji7O2bSJg0nsTgCc7rzcu7VP8bAA/5mXlzF0X+8PqG0
         piEG1DN+pW4VZJbIVk4eNNLiXwLxOAhecb4S+rUJdkmuo8B1QQ+uFclW2D4SJ+fYRK+D
         jZihZjkYiEz35fwkyWt0ljxWIxMi0IzkgQKRTt/JvuKtA/el6FXfyxkkO2svQnuy2BvI
         TqFyhv34n0EnVSm7YU0Oq6x4/Q8TQP6/A7ZLq9m4vfonjUOuqVZULfy7uZlSp6Zgbj8e
         eG3w==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:to:from;
        bh=BDTExIsPUoB1OmQyORHqvFbRYZjdsEar294g2orMngs=;
        b=vp+CvKQHzumh5n9PO7tXA+LyQdeZELdVQolxRY/GzH5BGqoXbHhrGPY0jUvBQLjCOU
         TQDlnX9tNsTmyj94kfBMKjCim7Q41h415AaPnLIrZswxDkB8cdlfaEG5TsmgFp9rre6s
         tT7H4fPpdDw7qY0i3BdNhDb5Sfb82tnSlwnEXPBtZU659twAFpp+scuYxQrwzQWuqsMR
         W14kVcXLYPSOWu8FBquZauRSuJHXhMqSTuBlAL0muAGXDNOWLaWS6KCEAA1+zrwbsUgX
         NCzsM6k9MCd523DGfskcirPfWDc6pxzCdjgsQuI1RVjH7WZRk80nCJdHt7fCXnyyp8wQ
         oKdw==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 209.222.10.136 as permitted sender) smtp.mailfrom=thiago@macieira.org
Original-Received: from smtp.macieira.info (arvernien.macieira.info. [209.222.10.136])
        by mx.google.com with ESMTPS id q11si53868qvr.54.2018.10.26.10.59.11
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 26 Oct 2018 10:59:11 -0700 (PDT)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 209.222.10.136 as permitted sender) client-ip=209.222.10.136;
Original-Received: from tjmaciei-mobl1.localnet (jfdmzpr05-ext.jf.intel.com [134.134.139.74])
	by smtp.macieira.info (Postfix) with ESMTPSA id 429401B497
	for <std-proposals@isocpp.org>; Fri, 26 Oct 2018 10:59:10 -0700 (PDT)
In-Reply-To: <CAF9gR9eYfBmL7rtc+uZ6L0q2jkQCPiJenwmfWGsDz4oBSx+yFw@mail.gmail.com>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 209.222.10.136 as permitted sender) smtp.mailfrom=thiago@macieira.org
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:40780
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/40780>

On Friday, 26 October 2018 09:41:02 PDT Roberto Hinz wrote:
> It's possible to implement a function that instantiates an api_string with
> an
> alternative allocator. But I would leave such function in a separate header.
> A copy of allocator object would not be stored as member variable of
> api_string, but inside the allocated memory, together with the reference
> counters.

So you need an extra memory allocation to use this class? Please account for 
that when discussing the benefits and disadvantages of your API.

> > But I don't see compilation time as an argument. It is most definitely
> > QoI:
> > for example, a compiler can react to #include <string> by inserting a pre-
> > compiled implementation into the AST.
> 
> I think only a compiler implementer can tell us how feasible is that.
> For example, how could a clang user switch from libc++ to libstdc++
> if std::string is pre-compiled ? If they didn't solve the problem yet,
> probably it's because it's not easy.

They didn't implement it because they didn't want it. The switch you mentioned 
is part of their objectives, as is the decoupling between the compiler and the 
standard library. Implementing a non-file #include mechanism would go against 
that.

What I am saying is that a compiler could choose to do that, under different 
circumstances.

> > So, can you describe the benefits your API would have or problems it would
> > solve, without referring to build times and ABI?
> 
> 1) Its copy constructor is always fast and never throws ( because it only
> needs to increment the reference count ). This makes it ideal to be
> stored inside exceptions

I personally like it this way. As you may be aware, QString is reference-
counted, as are most Qt container types.

But I am definitely not in the majority. The view of the majority of committee 
members and others in this list is that reference counting is bad, especially 
if (or is it "only if"?) it's coupled with Copy-on-Write.

> 2) If you want to create a api_string from a raw string that has static
> storage duration - like a string literal, which is very common - then you
> can skip the memory allocation and copy, by using the api_string_ref()
> function. This creates an api_string in "reference mode", that only
> references the char array without ever deleting it.

QString has that too, called fromRawData(), which allocates a memory block for 
the refcount and tracks that, but doesn't own the character data itself.

I'm changing it for Qt 6: instead, if the control block pointer is null, 
there's no reference counting needed. This could lead to further code merges 
between QString and QStringView, though prototypes need to be written still.

> In sum, I would say api_string aims to be ideal return string type.

It's worse than std::string_view, which has a trivial copy constructor. But it 
does support returning an allocated string and passing on its lifetime, which 
std::string_view can't do.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center



-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2314717.GH8Ag49nql%40tjmaciei-mobl1.

.
