220 33148 <CADbh+eSiSzAXC9UFrL6mWEVjLJdG=d7N03O0FV_iA0nv8i21YA@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Brittany Friedman <fourthgeek@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: template class to do default integral types initalization
Date: Fri, 7 Jul 2017 14:42:53 -0500
Lines: 169
Approved: news@gmane.org
Message-ID: <CADbh+eSiSzAXC9UFrL6mWEVjLJdG=d7N03O0FV_iA0nv8i21YA@mail.gmail.com>
References: <CA+fXA1B3TD29whzpCcuMH3H63nbp8tOWn1f3E7HBEnC6piYFkA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="94eb2c06001a770cb40553bf705c"
X-Trace: blaine.gmane.org 1499456581 10891 195.159.176.226 (7 Jul 2017 19:43:01 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 7 Jul 2017 19:43:01 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCHLPXGUXMJBBP6I77FAKGQEOMQJVIA@isocpp.org Fri Jul 07 21:42:56 2017
Return-path: <std-proposals+bncBCHLPXGUXMJBBP6I77FAKGQEOMQJVIA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f200.google.com ([209.85.161.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCHLPXGUXMJBBP6I77FAKGQEOMQJVIA@isocpp.org>)
	id 1dTZ9P-0002Jo-93
	for gclcip-std-proposals@m.gmane.org; Fri, 07 Jul 2017 21:42:51 +0200
Original-Received: by mail-yw0-f200.google.com with SMTP id z21sf33124228ywz.2
        for <gclcip-std-proposals@m.gmane.org>; Fri, 07 Jul 2017 12:42:56 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1499456576; cv=pass;
        d=google.com; s=arc-20160816;
        b=Og+C33PvQrXqpDRNS/Vqu9fYWLt8PYwnFta9zyUrDTDvkR13PwLIyDAyqoJrKaT+EL
         H4Lcd40qhmzAoLUDYQPM+kNLIELNuzZfDJYVTb752YFzqJVJbh0mwctJAHtaFAWEk3+1
         cAM/ECxGrvWD9LxDqIMFVNL1jbXXlHMWlelWo5RIAimFMczJsdgTpI/R1kh5Nd7mZOyz
         4AhyNhWL172l/G/8JoQntSSSIvAtytmABHGCqYN9Xr+T/4XIGVy5KcILmnJ8+pbfl78G
         gtj7q+DPDrvFWslDBvMD2IvZx+nVvojqfp/G3RbNN4jwOQFRjJymRPvS6BYzYm+GcE6O
         2nRg==
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:to:subject:message-id:date
         :from:references:in-reply-to:mime-version:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=VtOwSJs30I8C8P5o0XzxkL7fTFr+92FC6VF1NpcjaAE=;
        b=E4DfSbtsIh+x6X+Xx0CxEN84s04AC32D9Do746edtzbC4MFPeCXmEZ5t2qEYLPFL18
         OvAvuvME9vfrb7uLGw8i/3loInCbZCDRLY4C5mC6RTpm290B1suNGz9CTPh1SmVUJQ+Q
         xi1+BLkRoeivtFWGRmziRm5m16IHT3QlTsoZ7kHv3UPWr6L1PKnl+/2k3xS3MW2rWScL
         gNukUb+0YIm11w0kJUo3XtTwpwRAdqIrPI17O/AC0AwZHX2Hi3rZRsXjbMBGv7XM6dfv
         xCCSaPWHiquXdk9wuSkavHf6/JehVlDWR6gblHAvYlNaxtsS8aIr4/7rsI5nBzJrwiyS
         GRLQ==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=YHnWs4UL;
       spf=pass (google.com: domain of fourthgeek@gmail.com designates 2607:f8b0:400d:c09::230 as permitted sender) smtp.mailfrom=fourthgeek@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :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=VtOwSJs30I8C8P5o0XzxkL7fTFr+92FC6VF1NpcjaAE=;
        b=OV9qNSnyXREABBW4jkkwAUx0naOvTpnjhFOi8eWdfJp4tkCSLbuhfShnzrQDVaLz/M
         57Ht8y6BfUu8cDQMmgO2DT35pQ1HZf5aXR/jX/ulue4OQGG4K6up826wmDIMJHh0nJ9K
         ioidISKtOvFnAIsw8FqN0Ld1fgKjtOcHvj5V9DesDoCO/cyKCH7Hg7MDdewqoSZWj+4u
         Cw+1pjL0T+2aQ3JCUBJ8x2Q5vQ9/1ZamwfpCYnejwI0u+8RmgEITSJAU/u9l05QERyb5
         biiSwMstOshlq3PT8fThTi2uoVJ3UktZRIGETV6ISw2fa+rr1AR8p13TESbXEPgdM16Y
         cU/w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to: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=VtOwSJs30I8C8P5o0XzxkL7fTFr+92FC6VF1NpcjaAE=;
        b=eoerQkZVCkgoxddCT1E+PeUVaQNbPFWx3FjbhWA+sLMmtyJs9nvLF7kjhcWpCf2fQB
         5b8b2o4AAWsC3O6TDSf/ekk3c55odpJwYMNgpWuAQttYuJ8EXSYRdZ13bMLE6vOongBL
         q1km6ttT9ILs7lHdrziSNDjatvlfJBb7P1fy+7v6rnVQ5vtjByeQjLqLy7/bpElsk1/J
         +rzItrE1Bbz+8zyQqkvqLR+Q7sk2kV/VymG5IEkW/72dD0RyV5ValtZsiSBaqgJl7mVG
         UjnhoFEGXMV0r/1aRVj3blA6vms+lxdfkkBXgFC1T2biuor/mVUGuxf4jfC5ax+ziOU3
         YWew==
X-Gm-Message-State: AIVw111422S7FA5nkko6mW8Ir1bWzuGZskskOEU54G+dt16Mj+U0aOlB
	eJt1Y/65E/8jLbd3
X-Received: by 10.13.205.131 with SMTP id p125mr4726474ywd.64.1499456576228;
        Fri, 07 Jul 2017 12:42:56 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.172.92 with SMTP id m28ls1819829iti.4.gmail; Fri, 07 Jul
 2017 12:42:54 -0700 (PDT)
X-Received: by 10.55.113.197 with SMTP id m188mr64088961qkc.227.1499456574833;
        Fri, 07 Jul 2017 12:42:54 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1499456574; cv=none;
        d=google.com; s=arc-20160816;
        b=hvDEXgbKgz0STg6qgFU1Ig3o4F7q4ftpec5DM/UP1bnhKTDhzFftIoGW1DX3CQLeV8
         DyYIiok5X6BVxgAL7j805Ez4cJ6b7+VFyK/3PWskwLPTW56FNDz3zGXbxMkuO4h8iOJ1
         sVgikiKfHTplBIfGlUzJFsw5V1e7yutAfoDkl+2w2xUGrA8w4LQMvQhUb//0+Hhs67w4
         qNL5Mk8vNvq9RxtFTfWM6tOlpYAdQgZrvC54A2LThBI5W5hUnBaWbCY/7z8TWWUmswWL
         XjgTLLgB0ArSjD5ZxX1BaR8Lnhl0UG/Ml6hoCJT1aQMgg3YTrN+VwbFeBhkFK+s1sT9A
         L4Sg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:references:in-reply-to:mime-version
         :dkim-signature:arc-authentication-results;
        bh=VgLsgyBPN/quvtlxcay97Jmit1f13LEfJHvmilhOVKk=;
        b=x7Xk9XrgqBRPD1PJbqH+Ttjj42zjV0ogbmD2k3cl1Qp1dQKnEa8uTdj08YqljShJqz
         Y8LfgYrgH2knv+jXfWdGwK0ssiKA8NmsfsxNN835KR59T+1/Ynor9WUWDA93k2FO0FCM
         5XHZ4jKCOB9ixbRcZZPKtft/PK/b/73Y5nx5aW6Mk40w3NqZz1AC08q+ExOE2byM2b7n
         ei5sxjtV1mDYdlSG2kf2IgtQIehwk7UcQGH8/0ZUgstcPYh7nIl2OhRMajw/s208mCbH
         LndNqfU/tXVaQJG0QSZ9rbSyZ+923RIFJ8Z8X7vCJJc/WqRPq1ng/ZBQ8RWsNcr/h5fV
         eUmw==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=YHnWs4UL;
       spf=pass (google.com: domain of fourthgeek@gmail.com designates 2607:f8b0:400d:c09::230 as permitted sender) smtp.mailfrom=fourthgeek@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
Original-Received: from mail-qk0-x230.google.com (mail-qk0-x230.google.com. [2607:f8b0:400d:c09::230])
        by mx.google.com with ESMTPS id 35si4140825qtt.80.2017.07.07.12.42.54
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 07 Jul 2017 12:42:54 -0700 (PDT)
Received-SPF: pass (google.com: domain of fourthgeek@gmail.com designates 2607:f8b0:400d:c09::230 as permitted sender) client-ip=2607:f8b0:400d:c09::230;
Original-Received: by mail-qk0-x230.google.com with SMTP id 16so35850137qkg.2
        for <std-proposals@isocpp.org>; Fri, 07 Jul 2017 12:42:54 -0700 (PDT)
X-Received: by 10.55.158.19 with SMTP id h19mr64397078qke.201.1499456574260;
 Fri, 07 Jul 2017 12:42:54 -0700 (PDT)
Original-Received: by 10.140.20.202 with HTTP; Fri, 7 Jul 2017 12:42:53 -0700 (PDT)
In-Reply-To: <CA+fXA1B3TD29whzpCcuMH3H63nbp8tOWn1f3E7HBEnC6piYFkA@mail.gmail.com>
X-Original-Sender: fourthgeek@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.b=YHnWs4UL;       spf=pass (google.com: domain of
 fourthgeek@gmail.com designates 2607:f8b0:400d:c09::230 as permitted sender)
 smtp.mailfrom=fourthgeek@gmail.com;       dmarc=pass (p=NONE sp=NONE
 dis=NONE) header.from=gmail.com
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:33148
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33148>

--94eb2c06001a770cb40553bf705c
Content-Type: text/plain; charset="UTF-8"

On Fri, Jul 7, 2017 at 2:09 PM, ar <ar123456@gmail.com> wrote:

> Hi
>
> I am an application developer in the telcom industry with 30+ years of
> experience with 15+ years of heavy c++ for high end networking devices.
>
> I am working with code bases that started well  over 15 years ago and
> there is no end in sight, hence, writing maintainable code is of natural
> interest to me.
>
> One of the ideas in this area is to have all members to have default
> constructors. If encapsulating class is copyable/movable/assignable,
> members should have copy/move/assignment. Hence, adding new members would
> not require changes in constructors/assignments.
>
> Hence everybody have to write its own wrapper providing default
> constructor for integral types. I do believe that this approach has a lot
> of merit and it will be popular, hence, it makes sense to support it in
> standard library to avoid dealing with 10000 implementations of the same
> simple idea.
>
> The example is below.
>
> Thank you,
>
> Aleksey Romanov
>
> ===============================================================
>
>
> // Trivial wrapper class to add default initialization
> // to integral types.
> //
> // PROs:
> //   It seems that it will be used often
> //   It is 100% optional - does not affect existing of planned code
> //   It is trivially small
> //   It is used only in class definitions
> //   It does not require casts
> //
> // CONs:
> //   Yet another thing to track and document
>
> namespace std {
>
> template<typename T>
> class extype
> {
> public:
>     extype() : val_() {}
>     extype(T const& t) : val_(t) {}
>     extype(T&& t) : val_(move(t)) {}
>
>     operator const T&() const { return val_; }
>     operator T&() { return val_; }
> private:
>     T val_;
> };
>
> }
>
> // Usage example is below
> //
> // Note:
> //   1. The extype is used only inside class.
> //   2. Resolves code maintenance issue: if valC_ is added
> //      there is no need to make chages in constructors
> class X {
> public:
>     X() {}
>     ...
>     int valA() const { return valA_; }
>     int valB() const { return valB_; }
>
> private:
>     extype<int> valA_;
>     extype<int> valB_;
> };
>

It seems to me that    int valA_=0    is easier to type and understand than
   extype<int> valA_   . Do you disagree?

It looks like you can use -Weffc++  in clang/gcc to find uninitialized
members. Together this would address your concerns i think.

-- 
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/CADbh%2BeSiSzAXC9UFrL6mWEVjLJdG%3Dd7N03O0FV_iA0nv8i21YA%40mail.gmail.com.

--94eb2c06001a770cb40553bf705c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On Fri, Jul 7, 2017 at 2:09 PM, ar <span dir=3D"ltr">&lt;<a href=3D"mai=
lto:ar123456@gmail.com" target=3D"_blank">ar123456@gmail.com</a>&gt;</span>=
 wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.=
8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"lt=
r">Hi<br><br>I am an application developer in the telcom industry with
 30+ years of experience with 15+ years of heavy c++ for high end=20
networking devices.<br><br>I am working with code bases that started=20
well=C2=A0 over 15 years ago and there is no end in sight, hence, writing=
=20
maintainable code is of natural interest to me.<br><div><br></div><div>One
 of the ideas in this area is to have all members to have default=20
constructors. If encapsulating class is copyable/movable/assignable,=20
members should have copy/move/assignment. Hence, adding new members would n=
ot require changes in constructors/assignments.<br><br></div><div>Hence
 everybody have to write its own wrapper providing default constructor=20
for integral types. I do believe that this approach has a lot of merit=20
and it will be popular, hence, it makes sense to support it in standard=20
library to avoid dealing with 10000 implementations of the same simple=20
idea.<br><br></div><div>The example is below.<br></div><div><br></div><div>=
Thank you,<br><br></div><div>Aleksey Romanov<br><br>=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<wbr>=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D<wbr>=3D=3D=3D<br></div><div><br></div><div><br>// Trivial w=
rapper class to add default initialization<br>// to integral types.<br>//<b=
r>// PROs:<br>//=C2=A0=C2=A0 It seems that it will be used often<br>//=C2=
=A0=C2=A0 It is 100% optional - does not affect existing of planned code<br=
>//=C2=A0=C2=A0 It is trivially small<br></div><div>//=C2=A0=C2=A0 It is us=
ed only in class definitions<br></div><div>//=C2=A0=C2=A0 It does not requi=
re casts<br></div>//<br>// CONs:<br>//=C2=A0=C2=A0 Yet another thing to tra=
ck and document<br><br>namespace std {<br><br>template&lt;typename T&gt;<br=
>class extype<br>{<br>public:<br>=C2=A0=C2=A0=C2=A0 extype() : val_() {}<br=
>=C2=A0=C2=A0=C2=A0 extype(T const&amp; t) : val_(t) {}<br>=C2=A0=C2=A0=C2=
=A0 extype(T&amp;&amp; t) : val_(move(t)) {}<br>=C2=A0=C2=A0=C2=A0 <br>=C2=
=A0=C2=A0=C2=A0 operator const T&amp;() const { return val_; }<br>=C2=A0=C2=
=A0=C2=A0 operator T&amp;() { return val_; }<br>private:<br>=C2=A0=C2=A0=C2=
=A0 T val_;<br>};<br><br>}<br><br>// Usage example is below<br>//<br>// Not=
e:<br>//=C2=A0=C2=A0 1. The extype is used only inside class.<br>//=C2=A0=
=C2=A0 2. Resolves code maintenance issue: if valC_ is added<br>//=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 there is no need to make chages in constructors<br>cl=
ass X {<br>public:<br>=C2=A0=C2=A0=C2=A0 X() {}<br>=C2=A0=C2=A0=C2=A0 ...<b=
r>=C2=A0=C2=A0=C2=A0 int valA() const { return valA_; }<br>=C2=A0=C2=A0=C2=
=A0 int valB() const { return valB_; }<br><br>private:<br>=C2=A0=C2=A0=C2=
=A0 extype&lt;int&gt; valA_;<br>=C2=A0=C2=A0=C2=A0 extype&lt;int&gt; valB_;=
<br>};</div></blockquote><div><br></div>It seems to me that =C2=A0 =C2=A0in=
t valA_=3D0 =C2=A0 =C2=A0is easier to type and understand than =C2=A0 =C2=
=A0extype&lt;int&gt; valA_ =C2=A0 . Do you disagree?<div><br></div><div>It =
looks like you can use -Weffc++ =C2=A0in clang/gcc to find uninitialized me=
mbers. Together this would address your concerns i think.</div></div><br></=
div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CADbh%2BeSiSzAXC9UFrL6mWEVjLJdG%3Dd7N=
03O0FV_iA0nv8i21YA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CADbh%2BeSiSz=
AXC9UFrL6mWEVjLJdG%3Dd7N03O0FV_iA0nv8i21YA%40mail.gmail.com</a>.<br />

--94eb2c06001a770cb40553bf705c--

.
