220 35066 <1638034.bOiPUqA2XK@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: Re: std::vector, std::string attach/detach
 external buffer
Date: Fri, 20 Oct 2017 14:44:31 -0700
Lines: 39
Approved: news@gmane.org
Message-ID: <1638034.bOiPUqA2XK@tjmaciei-mobl1>
References: <f7b8bf44-80f9-4675-94b2-c876a353bd02@isocpp.org> <2688395.4cN1N1XxoH@tjmaciei-mobl1> <98f471c3-2a05-4dfa-8a48-b0ed8fb0212a@isocpp.org>
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 1508535891 2067 195.159.176.226 (20 Oct 2017 21:44:51 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 20 Oct 2017 21:44:51 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBRO4VHHQKGQE2SQY43I@isocpp.org Fri Oct 20 23:44:44 2017
Return-path: <std-proposals+bncBCB4TK757YBRBRO4VHHQKGQE2SQY43I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wr0-f199.google.com ([209.85.128.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB4TK757YBRBRO4VHHQKGQE2SQY43I@isocpp.org>)
	id 1e5f5j-0006WF-E3
	for gclcip-std-proposals@m.gmane.org; Fri, 20 Oct 2017 23:44:31 +0200
Original-Received: by mail-wr0-f199.google.com with SMTP id l8sf1779958wre.19
        for <gclcip-std-proposals@m.gmane.org>; Fri, 20 Oct 2017 14:44:39 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1508535878; cv=pass;
        d=google.com; s=arc-20160816;
        b=rZWGWdPer6Jb3WcrzrIOqEppnIIyYCTHHHGSYktB/hRqLc2w6xCZSHPetQ2idWWemR
         fRdjNz70/m7BBEijbAYq4gm+ImYB9XJwoMtxHIKGK4n206gVzZWfferD1zN4GG/Oh3P+
         4E0GOWxk8oA0Cfg18CTnLG6UpG484Po/05txS1fYXMcyXyMpDiIEQDyvn/M0zXuMjgiK
         TLIU3luw2TQNJ6KPU2vXJlxSu0bar2O6cTeocnFEkAV8pc20hyQv2N5uljhLicVmgeyB
         ZdiBQr2Rjr9LJzcL8E7J+pE3D2ss9CBvbw+76s3mOrFazF/qdWCNsFi4Azo9eSEIeGoW
         HKwg==
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
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=G40f30o3Al+Wri8VRU4zJFTpsSzrDas4roJ2OmI+eLg=;
        b=fMIqwnC+xXn6b3/PCZLH0SsEANXAHgbFDz3Q0+WJAcEJyeL9Bqt6MGkXMKU9XE8Zkj
         ejwjsbn+nfeMzi/GsjU/xpkj1Nu/7ID58LQoMQW4Nu/YrOqAD4x2y2PR9RcOn5FC+izr
         oA8GprSmqFQZ8xhKnso928wrrp53E9kg2mIIB/jADGbVyxfBCWWGhZdqeRghLG54rYts
         DucnpZw7esDkMIeuuDKbE61VSTEDuKhz2+HY9QLTT+PmbaJRTT/EPeTkMetVcvZpCwTw
         ARlaiz++4siqtNlK+UgFGJRIX4iPmNUKTpLAlz1hH3uq5T6sfzujqwmzWnCQ8o6Rf+be
         wLXQ==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 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=G40f30o3Al+Wri8VRU4zJFTpsSzrDas4roJ2OmI+eLg=;
        b=c0DCnnFu2ZTfiJww+3VuOgQc699n//qli9Xt34VY0Ko1l5aLs6Q80jIIo1Izz2eOJO
         JSRpX+SUKe0Ya0pQ6l/fiKRqKKKZPci61jFzB71EZCZFPFAcJxDbjhzGK1Nks2N6OUgb
         rajKMCgsFjslU0ZmV5sgIx3FRT4LVQpgX/RKypfG4Kcre/x55nuSCei7MTLqvD8+cYtS
         KbYfWNAbeAy7qABZu08q7e7PHcEWJFkTS2rD7KEb+3FcDAnGTpUy9fRmy37ABtl3uv6e
         n7jOdwUTiAZvsLV9FWn/GEX9nkEYXE0fXRypXH0qNPWprq53stLVUE0im1J+UGUDtAu3
         JSCA==
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=G40f30o3Al+Wri8VRU4zJFTpsSzrDas4roJ2OmI+eLg=;
        b=hiCxkpyo3plSrRHRm8QV9VCzLofs1GUwg1YXu6id9CuU1FHt8vNbR/ibdo3eHTvjWk
         SseqC/akb+RkpxUYhC1BmgSL1d/zwzL6c/hEDItmCtlDI0K+mcFQKT/w+HPb3Y6PsSwg
         pc5hfCFCHJCXBDNMRMiowhVEdEP7gkOPfa1eWn9F6QKSTJ93R3+54yQIR+LT8g5kEpcI
         fS3rqtVK1JJ45YBbepRP1EwhYqbVA778BO9QQmO1JTTRGgTcnt/6wPajeQHMjarI8P+b
         pfgTxFwfWNdyNOd6wHYwsj+yTNYyqSeZnEfUM7ARjPKWWWyJr0vQdRnablxoOt7U6pae
         0bpQ==
X-Gm-Message-State: AMCzsaWRBwCtJF5N59vp0V/FRCGpbE+ka5OuYbG1h2XwgWbEQeOEytSm
	2ka2C/MwaSVAhJGh5NT9L4emnA==
X-Google-Smtp-Source: ABhQp+Rr6yi18V8EP0Up/lsSrvTgTlgFeuiUXZdOZEOWocgzgrZ1hrmDGae9hbS7ohZjMZqAvc55wA==
X-Received: by 10.28.6.76 with SMTP id 73mr16657wmg.26.1508535878854;
        Fri, 20 Oct 2017 14:44:38 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.88.14 with SMTP id m14ls501871wmb.11.canary-gmail; Fri, 20
 Oct 2017 14:44:37 -0700 (PDT)
X-Received: by 10.223.146.37 with SMTP id 34mr5390502wrj.79.1508535877565;
        Fri, 20 Oct 2017 14:44:37 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1508535877; cv=none;
        d=google.com; s=arc-20160816;
        b=oGaFixXH/MSioPprUZ31aSvnMCPW2iU28S3KaQn/8DVdVqwIvacBWaZsuCaIPFhXBx
         Jsc9lz2TybVFR38V4irIr02hANiR4Gf0KLx1oi/oJWlxzvrSrQGueFrHCg1SrLwvNWnr
         wiZeUOqRRQlDonrqI4h/59C7BxSU8BtllFoQDbgiqC6nxsfaU/9A22SfV+hkgjzbJiP8
         Wdeda5yMl3yUdG7ID+Ize3WMMiOnFq2GNX9KYWWeQeGLLDbsc/eHWrYIqNEdpBaowR7B
         h2J8dkjwTrtBueu4uZMJMmFxiWXHQ43wFDMb11vNZ6osxYcDQcbki7EQgpuY97T2UGbJ
         ZxaA==
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:arc-authentication-results;
        bh=DALB2HC6up0f4esNpg+Si2A8i1BV6OVaqx4LugfYOvM=;
        b=fb3HdNigy1GvSsf/90Z8yeotykzIMFC9Wqa7+tyubal0A/6T8y1BSViDGWsa9ZBXP4
         S8+OfJcWwsjUQTAd6YOPCIFwCVbzAZwlfXIEuoJAB+XOSpTWd0yXFjkVZL7J5mgY6mok
         O4JSDLNb9LGmNg5noAw8gB7Qjl/EP30+jXKHnm9zVebCQLntuF6K3P2q7lmdq06YRTLC
         pSyvO42SdqG9wYDLdNjj8Pby2qw+1G6w5Q5P2UcNecZmexB8rxO9sYI0CeHcGTQTPyzN
         O5azlJS2wyo7LTnB+gm1oOzicdsSI6k5Nrjt6L9UZ7rHOkSTZpuZX/XDmfqttaH6fLBB
         mS6Q==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) smtp.mailfrom=thiago@macieira.org
Original-Received: from gondolin.macieira.info (gondolin.macieira.info. [78.47.120.188])
        by mx.google.com with ESMTP id p77si1527956wma.88.2017.10.20.14.44.36
        for <std-proposals@isocpp.org>;
        Fri, 20 Oct 2017 14:44:36 -0700 (PDT)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) client-ip=78.47.120.188;
Original-Received: from tjmaciei-mobl1.localnet (jfdmzpr04-ext.jf.intel.com [134.134.139.73])
	by gondolin.macieira.info (Postfix) with ESMTPSA id D7D5211B50A
	for <std-proposals@isocpp.org>; Fri, 20 Oct 2017 14:44:33 -0700 (PDT)
In-Reply-To: <98f471c3-2a05-4dfa-8a48-b0ed8fb0212a@isocpp.org>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 78.47.120.188 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-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:35066
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35066>

On Friday, 20 October 2017 14:11:49 PDT Nicol Bolas wrote:
> > Note, however, the consequence:
> >         char *ptr = cstring.detach_buffer();
> > 
> > may fail.
> 
> ... I disagree; this *must* succeed. But it doesn't have to *empty* the
> buffer, just like moving from a `basic_string` can still do a copy if the
> string is in the SSO buffer. This should be able to allocate memory, and
> therefore represents a potentially throwing operation.

Read: it may fail :-)

> This is another reason why I feel that the "detach_buffer" mechanism needs
> to be wrapped in a type. So instead of getting a `char*`, you get:
> 
> buffer<char, Allocator> buf = cstring.detach_buffer();
> 
> `buf` now owns that memory, with full RAII semantics. You can call
> `buf.data()` to get a pointer to the array, but it doesn't have any of the
> container machinery like `begin/end/operator[]/insert/remove/etc`. It's
> just a buffer with a size, capacity, and allocator.

I don't see how this helps with this particular problem. If the string was 
SSO, then detach_buffer() may still throw, because it can't point to the 
cstring object's area.

It may be a good idea as a general principle, though.

-- 
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/1638034.bOiPUqA2XK%40tjmaciei-mobl1.

.
