220 33147 <CA+fXA1B3TD29whzpCcuMH3H63nbp8tOWn1f3E7HBEnC6piYFkA@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: ar <ar123456@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: template class to do default integral types initalization
Date: Fri, 7 Jul 2017 15:09:28 -0400
Lines: 150
Approved: news@gmane.org
Message-ID: <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="001a1145b8deec121d0553bef876"
X-Trace: blaine.gmane.org 1499454570 29920 195.159.176.226 (7 Jul 2017 19:09:30 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 7 Jul 2017 19:09:30 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDHJNJE2R4MRB2NY77FAKGQEDAVHIFA@isocpp.org Fri Jul 07 21:09:26 2017
Return-path: <std-proposals+bncBDHJNJE2R4MRB2NY77FAKGQEDAVHIFA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb0-f199.google.com ([209.85.213.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDHJNJE2R4MRB2NY77FAKGQEDAVHIFA@isocpp.org>)
	id 1dTYd3-0007V2-MX
	for gclcip-std-proposals@m.gmane.org; Fri, 07 Jul 2017 21:09:25 +0200
Original-Received: by mail-yb0-f199.google.com with SMTP id l5sf31431254ybb.6
        for <gclcip-std-proposals@m.gmane.org>; Fri, 07 Jul 2017 12:09:31 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1499454570; cv=pass;
        d=google.com; s=arc-20160816;
        b=XOh9kX95OPcA/WITBAltmg68SFZ1puuu/6lkyLFtAQSvjgWDuHuB7WxyWRnp4Fm8mH
         dFFVUtvfaiA1JLbvjkEXpkgmPoyVNVaalc6/Y/+aZXFN/cHNB+qmKX09I5HPsPIIwt+s
         ruG+ZDHMCyIKqjfoNt1R3KiZvBjvi8NFXGpls0nzxnL1CRqyXpwt8f9AyBibSLlnjyF2
         eG6guEAc3w1Jt5x/w8XtOrm6ljnES9wjjvbOiHyC50UPQlbwMaqIFhkh0ECC/Gols9dv
         Flw7hve09Z57jQitQRdB0NJnqtSQEn1AYODAezOh5Vd5v4TgIn1VdPMvBSKsXTvrYJYX
         3nnw==
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:mime-version:arc-authentication-results:arc-message-signature
         :dkim-signature:arc-authentication-results;
        bh=O77024Gj9hg2XrQxrqAZ/sqz+9ctw0CyVITjNAn5lB8=;
        b=gH7RTYbqoBWHORteWQ3M4Xe+IFbNVqCtua21A4DuDKHZkTMXigA7JbwtEirTJNcPO6
         G/CgrDWYFsfSQ4qej3LgXpovK82MXlp65hL4qcGEmrtxRgoa88tys2/FrgnwG876dw4P
         meYMioyYkhmB3ZiG8K1pi+rKkqs6tkopDE62YCU9pM/nst7Pyc7WGnh+MMbdmpN16cyA
         HoXPp+VNtlWCu4CHgEAmwerQRraVC7rgggQCA4oEYZHFp1Y4mkVfXAHILsHzE8vW7S+j
         lFrbXZ0t7ECmyhQhnr+inc3oJPTUldVSVVVUOHoLin6Qu8UTEet1YnJLITcJtaUoc1j8
         URJg==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=gfqkkmpt;
       spf=pass (google.com: domain of ar123456@gmail.com designates 2607:f8b0:400d:c09::235 as permitted sender) smtp.mailfrom=ar123456@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: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=O77024Gj9hg2XrQxrqAZ/sqz+9ctw0CyVITjNAn5lB8=;
        b=sQLBV1vZRSlJIb9aLcZF+E/7yT63pmMZwR0spIilRgWgfgP5IAXtpRRcgD6cH6pW78
         Rpt46yCj3QdI9beFNu7M8XqsiNsISnC+VzAdIm+A3wf5Uu8xsneSW5X3ksXDI/xZEJXj
         D9jOK2F3jBcXA4U7BmfkGw2MwZFyBvsrzmmv9gUi1ag131MQGABnxPnTHSQZBrYGgOpb
         /5qtCMY9rkNVWVtksanQG1H6QleA0kdHcX20K40+hi1ZcTAnxAy91BoTGy5StkPaOTSX
         DKKzzDdN4TxLvAZF3zkrka4MYqDFH6Uiw1+j+jOE+qyNhfO13LB4swMWtKRvbkrbvYIr
         NlRQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version: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=O77024Gj9hg2XrQxrqAZ/sqz+9ctw0CyVITjNAn5lB8=;
        b=T/r/o8KYjRP+RYJTmXOzjjpO1uycI9jqJxPMKDbtDA8lqQp5+6BJW/4KgV3QEXpM4e
         +UPabAgtrd8rQgUJSE5V7nppWVsiYMzp3jRRUZbcVdwqEkJX+pyQjb2CQEZFiSh/TYTJ
         oEU9cHWJvo1xWTYKNYz3W4Roe28uBiuOhjq06FWs90fS2aDJFQMjd4vequQjek9N5DIB
         qCtHWojkGi7Lo6MumzfZzjPCfXFSQTwZkm5dkoIKkoQc0s60GJcgwZRJtIeRTwHNNmlb
         HMYdUpZSotM/RU+/MbxLNajnQf1P2CMJPoW7YwUkhr0CWNACBoQXs/jiwxwSk0rAHTKE
         H1Ag==
X-Gm-Message-State: AIVw113fK4TF1p9epicseiKnWjHWVfXuFolsMoMQRCZlm/BIWJG776VU
	mKCxti9dYT2gIl2q
X-Received: by 10.129.89.134 with SMTP id n128mr4881724ywb.0.1499454570655;
        Fri, 07 Jul 2017 12:09:30 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.82.3 with SMTP id d3ls1026280itb.13.gmail; Fri, 07 Jul 2017
 12:09:29 -0700 (PDT)
X-Received: by 10.55.25.198 with SMTP id 67mr66016894qkz.53.1499454569191;
        Fri, 07 Jul 2017 12:09:29 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1499454569; cv=none;
        d=google.com; s=arc-20160816;
        b=KLxEl7hMPbDiP6zT9+sSyXWOAFcnXkHXUxbb/UhHrVMq6yE+mUK2kkaJtWM86N7GGh
         Kkvp6eaO5zmLSmHXC+6uc75VtRDaSp4JXbdgTr49XdbhUinFb3iOLnAJfxgsOv6NjZ2D
         siRP5HEN+zSiY3DpImK/WlxpvMW/omMuspbLX1zBWS1N2Pf6/O5DOD+tpjvSDuhRmrrD
         BjDd+yacC/EDrTidTIoupKqMXWMi2o8gFVXYlJXtWjsxmJ+42YxKlf4C+qhK7WFdpV7Y
         eogU2vFVzoaeW2jFXORxq1vVQVpQPsN86Jud77uiG70wsHcoe94jj0aQvcI3jazIwFEM
         JdRw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:mime-version:dkim-signature
         :arc-authentication-results;
        bh=eO6icEUdsRmv2AL2CwAoxHd1xiLI9xz44giXgfPZu+E=;
        b=xGj1+3I9AbXINVQy7emcGYQ1bkw/1unLXN0kktnXZcSAgrjdSf74ibJdL0yCUX8vMc
         xtimH9y3rDG5D6FOWOJD8tuGRMl1i39Da3pewP30mQGdavcY/Zd8B3ISwTnVL5I9DL6W
         zvTRdhXjSnfHIEzXHyv7LEWwMExj5FNqSfT3gfv3mJ8BEarEA9jbF5rWLiDWKY8T2SEE
         0xDaIn5eD3y6g6xYve7Hqbe6PdnU+Vv/2vceaV/B2VTttvjrRoIt3zj3qDPSLwmpBrP5
         WMQodphPkQoJwLSTarz0GFJKugVJGEbzRtMOvc63wPKJrFDP+PnQIHp1fo6zKv4XVhlC
         oVlQ==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=gfqkkmpt;
       spf=pass (google.com: domain of ar123456@gmail.com designates 2607:f8b0:400d:c09::235 as permitted sender) smtp.mailfrom=ar123456@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
Original-Received: from mail-qk0-x235.google.com (mail-qk0-x235.google.com. [2607:f8b0:400d:c09::235])
        by mx.google.com with ESMTPS id v5si3904564qkl.123.2017.07.07.12.09.29
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 07 Jul 2017 12:09:29 -0700 (PDT)
Received-SPF: pass (google.com: domain of ar123456@gmail.com designates 2607:f8b0:400d:c09::235 as permitted sender) client-ip=2607:f8b0:400d:c09::235;
Original-Received: by mail-qk0-x235.google.com with SMTP id v143so35143860qkb.0
        for <std-proposals@isocpp.org>; Fri, 07 Jul 2017 12:09:29 -0700 (PDT)
X-Received: by 10.55.207.140 with SMTP id v12mr62731036qkl.49.1499454568664;
 Fri, 07 Jul 2017 12:09:28 -0700 (PDT)
Original-Received: by 10.140.25.141 with HTTP; Fri, 7 Jul 2017 12:09:28 -0700 (PDT)
X-Original-Sender: ar123456@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.b=gfqkkmpt;       spf=pass (google.com: domain of
 ar123456@gmail.com designates 2607:f8b0:400d:c09::235 as permitted sender)
 smtp.mailfrom=ar123456@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:33147
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33147>

--001a1145b8deec121d0553bef876
Content-Type: text/plain; charset="UTF-8"

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_;
};

-- 
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/CA%2BfXA1B3TD29whzpCcuMH3H63nbp8tOWn1f3E7HBEnC6piYFkA%40mail.gmail.com.

--001a1145b8deec121d0553bef876
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi<br><br>I am an application developer in the telcom indu=
stry 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>

<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/CA%2BfXA1B3TD29whzpCcuMH3H63nbp8tOWn1=
f3E7HBEnC6piYFkA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CA%2BfXA1B3TD29=
whzpCcuMH3H63nbp8tOWn1f3E7HBEnC6piYFkA%40mail.gmail.com</a>.<br />

--001a1145b8deec121d0553bef876--

.
