220 10458 <2ce5f43b-9a89-457c-afa1-71ba867e66ef@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: maksimpustovoyt@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Add compiler time attributes like c#
Date: Wed, 30 Apr 2014 17:43:10 -0700 (PDT)
Lines: 199
Approved: news@gmane.org
Message-ID: <2ce5f43b-9a89-457c-afa1-71ba867e66ef@isocpp.org>
References: <e9533cfc-f35c-4313-aaaf-a6d3d8aa00f9@isocpp.org>
 <CAOU91OOiEnyF6m=8hetJxCsBxs1UkRYu3xn_LOFuMk0xuv8WcQ@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_2930_9961398.1398904990735"
X-Trace: ger.gmane.org 1398905000 21709 80.91.229.3 (1 May 2014 00:43:20 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 1 May 2014 00:43:20 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCRP3Q4MT4MRBH5RQ2NQKGQETBI4XFA@isocpp.org Thu May 01 02:43:15 2014
Return-path: <std-proposals+bncBCRP3Q4MT4MRBH5RQ2NQKGQETBI4XFA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oa0-f69.google.com ([209.85.219.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCRP3Q4MT4MRBH5RQ2NQKGQETBI4XFA@isocpp.org>)
	id 1Wff5l-0004Jw-9j
	for gclcip-std-proposals@m.gmane.org; Thu, 01 May 2014 02:43:13 +0200
Original-Received: by mail-oa0-f69.google.com with SMTP id i7sf13147795oag.0
        for <gclcip-std-proposals@m.gmane.org>; Wed, 30 Apr 2014 17:43:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=S/ihbpZbAN3TS8w+fMsvBtk/xinPHFOkC7vqWZo/ATg=;
        b=Unyw05nz9ym5gCdDpP2flXwSdvmPu3MsvPA6yMxwsIKDGzBb1YOg2OoZ6V/RhNPysy
         /y08S3ML+OJ5YsTbYd/PW2OzwpNakVTACCfgw8GayGcoGpgwaO8hm5evGS+7A3z7qon7
         0vIGKQZHdvSFP+AVw0NY+AfX0zh0BWfuC6yO3SBxZVWFnrfkpwUsawPge+DVnu2CDB1B
         YU2SwfoocrNbVsKKIGB+T096ed0R2YrxDZRzg9pgwpMMdOjiyiFAS55q9Ky7WaP/3G/B
         wwXheU3O9kSyUQPHYDA7A66fPPNxWpnw4Hvk+391NXFyZns1/gcuTcAriJkjAjWOQ0rZ
         zqCA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=S/ihbpZbAN3TS8w+fMsvBtk/xinPHFOkC7vqWZo/ATg=;
        b=XV5lc/PE1mYs+KaKJI54NPxDaa4bTuwSOKCCtP2i4HVRwwXc+CdAdldexBjtkC7E1a
         nSUdUNsdiQcxqTlV7Ysh/Piz4hKMu5rvNeB7wmYAhHI+EykogYJOWjPZIeFqQKC5smWw
         mxrKJ61ptaYr/q3toCRGf5asAKYtV7p0MmfONwq2C46E9cW4j1B+w4KO40k6G0+MsJUA
         nllaoHkUowskmrtwVMQg0t5m1frkinTsTZ2kmj6U4DD9nTM1igPwAucCDzyCVs1CXMRe
         6xW+Or5k2Q4qFBnloKjWY2epHDqhnCWfXVw5NZ6JaXFpk/mFM3/yb3GH/UiE45gHFMd5
         wi3A==
X-Gm-Message-State: ALoCoQl28iJn2O4JM35h6yhIpZ6sdiZMNB1E9iSpB8wFhMFlW/iEO1DT6iym7S/9YbsSjtgjcFY5
X-Received: by 10.43.117.71 with SMTP id fl7mr3950340icc.24.1398904992289;
        Wed, 30 Apr 2014 17:43:12 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.138.69 with SMTP id qo5ls442286obb.34.gmail; Wed, 30 Apr
 2014 17:43:11 -0700 (PDT)
X-Received: by 10.182.243.227 with SMTP id xb3mr55355obc.17.1398904991249;
        Wed, 30 Apr 2014 17:43:11 -0700 (PDT)
In-Reply-To: <CAOU91OOiEnyF6m=8hetJxCsBxs1UkRYu3xn_LOFuMk0xuv8WcQ@mail.gmail.com>
X-Original-Sender: maksimpustovoyt@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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:10458
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/10458>

------=_Part_2930_9961398.1398904990735
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Wednesday, April 30, 2014 8:13:44 AM UTC-4, Klaim - Jo=C3=ABl Lamotte wr=
ote:
>
> C++11 already have =E2=80=8Battributes. See:=20
> en.cppreference.com/w/cpp/language/attributes
> Or are you suggesting specific attributes to be standardised?
> If yes, then your example is not clear at all to me.
>

This is different than C++11 attributes.

This is extendable Metadata about class which you can use in real time=20
or sometimes it's called "reflection"

For example, I want to print my object in nice format. I can do something=
=20
like that:

*[AttributeExtension]* // This predefine attribute tells compiler that this=
=20
class can be used as an Attribute for other classes:
struct MyAttribute {
    string Name;
    string Description;
    MyAttribute(string name; string description=3D "") : Name(name),=20
Description(description) {}
}
*[AttributeExtension]* // This predefine attribute tells compiler that this=
=20
class can be used as an Attribute for other classes:
struct AgeRange {=20
    int Minum;
 int Maximum;
 AgeRange(int minum; int maximum)  Minum(minum), Maximum(maximum) {}
}


.... some time later in code...

*[METADATA(true)]* // tells compiler to geneate meta data about class Perso=
n
                                 // Compiler generates static Metadata=20
classes such as Person::Class::MyAttribute,=20
Person::Member::FirstName::MyAttribute, ...

*[MyAttribute("Person", "Person Info")]* // calls constructor=20
Person::Class::MyAttribute::MyAttribute("Person", "Person Info")
struct Person {
 [MyAttribute("Fist Name")] // calls constructor=20
Person::Member:FirstName::MyAttribute::MyAttribute("Fist Name")
 string FirstName;
 [MyAttribute("Last Name", "Person's last name")] // calls=20
constructor Person::Member:FirstName::MyAttribute::MyAttribute("Last Name",=
=20
"Person's last name")=20
 string LastName;
 [AgeRange(18,50)] // calls constructorPerson::Member::
AgeRange::AgeRange(18,50)=20
 int ValidAge;
}


.... some time later in code...

bool CanRegisterPerson(Person &person) {=20
 if (person.ValidAge < *Person::Member::ValidAge::AgeRange::Minimum*)=20
return false;=20
 if (person.ValidAge > *Person::Member::ValidAge::AgeRange::Maximum*)=20
return false;
 return true;
}

bool RegisterPerson(Person &person) {=20
 if (!CanRegisterPerson(person)) {
  printf("Cannot register person %s:%s, %s:%s because age %d must be in=20
between %d and %d\n"
   ,*Person::Member::FirstName::MyAttribute::Name*.c_str() // compiler=20
generate static data member Name ()
   ,person.FistName.c_str()
   ,*Person::Member::LastName::MyAttribute::Name*.c_str()
   ,person.LastName.c_str()  =20
   ,person.Age
   ,*Person::Member::ValidAge::AgeRange::Minimum*
   ,*Person::Member::ValidAge::AgeRange::Maximum*
   return false;
  );
  return true; =20
 }



}=20

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_2930_9961398.1398904990735
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Wednesday, April 30, 2014 8:13:44 AM UTC-4, Kla=
im - Jo=C3=ABl Lamotte wrote:<blockquote class=3D"gmail_quote" style=3D"mar=
gin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204,=
 204); border-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr">=
C++11 already have&nbsp;=E2=80=8Battributes. See:&nbsp;<a onmousedown=3D"th=
is.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fen.cppreference.com%2=
Fw%2Fcpp%2Flanguage%2Fattributes\46sa\75D\46sntz\0751\46usg\75AFQjCNH9Dk3GS=
NX7l_TUTRgP10mO8NSFVQ';return true;" onclick=3D"this.href=3D'http://www.goo=
gle.com/url?q\75http%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Flanguage%2Fatt=
ributes\46sa\75D\46sntz\0751\46usg\75AFQjCNH9Dk3GSNX7l_TUTRgP10mO8NSFVQ';re=
turn true;" href=3D"http://en.cppreference.com/w/cpp/language/attributes" t=
arget=3D"_blank">en.cppreference.com/w/<wbr>cpp/language/attributes</a><div=
>Or are you suggesting specific attributes to be standardised?<div>
If yes, then your example is not clear at all to me.</div></div></div></blo=
ckquote><div><div><br>This is different than C++11 attributes.</div><p>This=
 is extendable Metadata about class which you can use in real time or&nbsp;=
sometimes it's called&nbsp;"reflection"</p><p>For example, I want to print =
my object in nice format. I can do something like that:</p><p><strong>[Attr=
ibuteExtension]</strong> <font color=3D"#38761d">// This predefine attribut=
e tells compiler that this class can be used as an Attribute for other clas=
ses:</font><br>struct MyAttribute {<br>&nbsp;&nbsp;&nbsp; string Name;<br>&=
nbsp;&nbsp;&nbsp; string Description;<br>&nbsp;&nbsp;&nbsp; MyAttribute(str=
ing name; string description=3D "") : Name(name), Description(description) =
{}<br>}<br><strong>[AttributeExtension]</strong> <font color=3D"#38761d">//=
 This predefine attribute tells compiler that this class can be used as an =
Attribute for other classes:</font><br>struct AgeRange {&nbsp;<br>&nbsp;&nb=
sp;&nbsp; int Minum;<br>&nbsp;int Maximum;<br>&nbsp;AgeRange(int minum; int=
 maximum)&nbsp; Minum(minum), Maximum(maximum) {}<br>}</p><p><br></p><div><=
font color=3D"#134f5c">... some time later in code...</font></div><font col=
or=3D"#134f5c"></font><div><br><strong>[METADATA(true)]</strong> <font colo=
r=3D"#38761d">// tells compiler to geneate meta data about class Person</fo=
nt></div><div><font color=3D"#38761d">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; //&nbsp;Compiler generates static Metadata classes such as <font colo=
r=3D"#38761d"><font color=3D"#38761d">Person::Class::MyAttribute, Person::M=
ember::FirstName::MyAttribute, ...</font></font></font></div><div><font col=
or=3D"#38761d"></font><br><strong>[MyAttribute("Person", "Person Info")]</s=
trong> <font color=3D"#6aa84f">// calls constructor Person::Class::MyAttrib=
ute::MyAttribute("<wbr>Person", "Person Info")</font><br>struct Person {<br=
>&nbsp;[MyAttribute("Fist Name")] <font color=3D"#6aa84f">// calls construc=
tor Person::Member:FirstName::MyAttribute::MyAttribute("Fist Name")</font><=
br>&nbsp;string FirstName;<br>&nbsp;[MyAttribute("Last Name", "Person's las=
t name")] <font color=3D"#6aa84f">// calls constructor&nbsp;Person::Member:=
FirstName::MyAttribute::MyAttribute("Last Name", "Person's last name")</fon=
t>&nbsp;<br>&nbsp;string LastName;<br>&nbsp;[AgeRange(18,50)]<font color=3D=
"#38761d"> // calls constructor<font color=3D"#6aa84f">Person::Member::</fo=
nt>AgeRange::AgeRange(18,50)</font>&nbsp;<br>&nbsp;int ValidAge;<br>}</div>=
<p><br><font color=3D"#0b5394">... some time later in code...</font></p><p>=
bool CanRegisterPerson(Person &amp;person) {&nbsp;<br>&nbsp;if (person.Vali=
dAge &lt; <strong>Person::Member::ValidAge::<wbr>AgeRange::Minimum</strong>=
) return false;&nbsp;<br>&nbsp;if (person.ValidAge &gt; <strong>Person::Mem=
ber::ValidAge::<wbr>AgeRange::Maximum</strong>) return false;<br>&nbsp;retu=
rn true;<br>}</p><p>bool RegisterPerson(Person &amp;person) {&nbsp;<br>&nbs=
p;if (!CanRegisterPerson(person)) {<br>&nbsp;&nbsp;printf("Cannot register =
person %s:%s, %s:%s because age %d must be in between %d and %d\n"<br>&nbsp=
;&nbsp;&nbsp;,<strong>Person::Member::FirstName:<wbr>:MyAttribute::Name</st=
rong>.c_str() //&nbsp;compiler generate static data member Name&nbsp;()<br>=
&nbsp;&nbsp;&nbsp;,person.FistName.c_str()<br>&nbsp;&nbsp;&nbsp;,<strong>Pe=
rson::Member::LastName::<wbr>MyAttribute::Name</strong>.c_str()<br>&nbsp;&n=
bsp;&nbsp;,person.LastName.c_str()&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;,=
person.Age<br>&nbsp;&nbsp;&nbsp;,<strong>Person::Member::ValidAge::<wbr>Age=
Range::Minimum</strong><br>&nbsp;&nbsp;&nbsp;,<strong>Person::Member::Valid=
Age::<wbr>AgeRange::Maximum</strong><br>&nbsp;&nbsp;&nbsp;return false;<br>=
&nbsp;&nbsp;);<br>&nbsp;&nbsp;return true;&nbsp;&nbsp;<br>&nbsp;}</p><p><br=
></p><p><br></p><p>}&nbsp;</p></div></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2930_9961398.1398904990735--

.
