Topic: Type Expressions


Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Fri, 11 Jul 2014 16:31:15 -0700 (PDT)
Raw View
------=_Part_5_25772121.1405121475407
Content-Type: text/plain; charset=UTF-8

Here is a fun little idea:

    template<typename T1, typename T2>
    using operator+ = std::pair<T1, T2>;

    struct A{};  struct B {};

    using C = A + B;

    static_assert(std::is_same_v<C, std::pair<A,B>>); // ok

    int + float x = {42, 2.0}; // lol

    template<typename T1, typename T2>
    using operator| = boost::variant<T1, T2>;

    template<typename T1, typename... Ts>
    using operator| <T1, boost::variant<Ts...>> = boost::variant<T1, Ts...>;

    struct X{}; struct Y{}; struct Z{}

    using W = X | Y | Z;

    static_assert(std::is_same_v<W, boost::variant<X,Y,Z>>);

Now for some real fun:

    template<char... cs>
    using operator""s = string_type<cs...>;

    template<char... cs1, char... cs2>
    using operator+ <string_type<cs1...>, string_type<cs2...>> =
string_type<cs1..., cs2...>;

    using S1 = "foo"s + "bar"s;
    using S2 = "foobar"s;

    static_assert(std::is_same_v<S1, S2>); // ok

    template<typename T> struct X = ...;

    using Y = X<"foo"s>;

    template<typename T>
    using operator* = std::shared_ptr<T>;

    struct S {};

    *S p = new S; // more lol

Notice I only said it was a fun idea, nowhere was it claimed it was also a
good one. :)

Enjoy,
Andrew.

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_5_25772121.1405121475407
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Here is a fun little idea:<div><br></div><div>&nbsp; &nbsp=
; template&lt;typename T1, typename T2&gt;</div><div>&nbsp; &nbsp; using op=
erator+ =3D std::pair&lt;T1, T2&gt;;</div><div><br></div><div>&nbsp; &nbsp;=
 struct A{}; &nbsp;struct B {};</div><div><br></div><div>&nbsp; &nbsp; usin=
g C =3D A + B;</div><div><br></div><div>&nbsp; &nbsp; static_assert(std::is=
_same_v&lt;C, std::pair&lt;A,B&gt;&gt;); // ok</div><div><br></div><div>&nb=
sp; &nbsp; int + float x =3D {42, 2.0}; // lol</div><div><br></div><div>&nb=
sp; &nbsp; template&lt;typename T1, typename T2&gt;</div><div>&nbsp; &nbsp;=
 using operator| =3D boost::variant&lt;T1, T2&gt;;</div><div><br></div><div=
>&nbsp; &nbsp; template&lt;typename T1, typename... Ts&gt;</div><div>&nbsp;=
 &nbsp; using operator| &lt;T1, boost::variant&lt;Ts...&gt;&gt; =3D boost::=
variant&lt;T1, Ts...&gt;;</div><div><br></div><div>&nbsp; &nbsp; struct X{}=
; struct Y{}; struct Z{}</div><div><br></div><div>&nbsp; &nbsp; using W =3D=
 X | Y | Z;</div><div><br></div><div>&nbsp; &nbsp; static_assert(std::is_sa=
me_v&lt;W, boost::variant&lt;X,Y,Z&gt;&gt;);</div><div><br></div><div>Now f=
or some real fun:</div><div><br></div><div>&nbsp; &nbsp; template&lt;char..=
.. cs&gt;</div><div>&nbsp; &nbsp; using operator""s =3D string_type&lt;cs...=
&gt;;</div><div><br></div><div>&nbsp; &nbsp; template&lt;char... cs1, char.=
... cs2&gt;</div><div>&nbsp; &nbsp; using operator+ &lt;string_type&lt;cs1..=
..&gt;, string_type&lt;cs2...&gt;&gt; =3D string_type&lt;cs1..., cs2...&gt;;=
</div><div><br></div><div><span style=3D"font-size: 13px;">&nbsp; &nbsp; us=
ing S1 =3D "foo"s + "bar"s;</span><br></div><div>&nbsp; &nbsp; using S2 =3D=
 "foobar"s;</div><div><br></div><div>&nbsp; &nbsp; static_assert(std::is_sa=
me_v&lt;S1, S2&gt;); // ok</div><div><br></div><div>&nbsp; &nbsp; template&=
lt;typename T&gt; struct X =3D ...;</div><div><br></div><div>&nbsp; &nbsp; =
using Y =3D X&lt;"foo"s&gt;;</div><div><br></div><div>&nbsp; &nbsp; templat=
e&lt;typename T&gt;</div><div>&nbsp; &nbsp; using operator* =3D std::shared=
_ptr&lt;T&gt;;</div><div><br></div><div>&nbsp; &nbsp; struct S {};</div><di=
v><br></div><div>&nbsp; &nbsp; *S p =3D new S; // more lol</div><div><br></=
div><div>Notice I only said it was a fun idea, nowhere was it claimed it wa=
s also a good one. :)</div><div><br></div><div><span style=3D"font-size: 13=
px;">Enjoy,</span><br></div><div>Andrew.</div><div><br></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_5_25772121.1405121475407--

.


Author: David Krauss <potswa@gmail.com>
Date: Sat, 12 Jul 2014 07:38:31 +0800
Raw View
--Apple-Mail=_3B9D816D-07D8-435E-A210-F25D0B8B2AE8
Content-Type: text/plain; charset=ISO-8859-1


On 2014-07-12, at 7:31 AM, Andrew Tomazos <andrewtomazos@gmail.com> wrote:

> Notice I only said it was a fun idea, nowhere was it claimed it was also a good one. :)

Amusing, for sure.

The grammar is already overloaded out the wazoo, maybe better to disambiguate the type-operator like <+> or [[+]].

Given this level of metaprocessing, might as well use tuple (with sequence concatenation semantics) instead of pair :P

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--Apple-Mail=_3B9D816D-07D8-435E-A210-F25D0B8B2AE8
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;07&ndash;12, at 7:31 AM, Andrew Tomazos &lt;<a href=3D"mailto:andrewt=
omazos@gmail.com">andrewtomazos@gmail.com</a>&gt; wrote:</div><br class=3D"=
Apple-interchange-newline"><blockquote type=3D"cite"><div dir=3D"ltr"><div>=
Notice I only said it was a fun idea, nowhere was it claimed it was also a =
good one. :)</div></div></blockquote><div><br></div><div>Amusing, for sure.=
</div><div><br></div><div>The grammar is already overloaded out the wazoo, =
maybe better to disambiguate the type-operator like <font face=3D"Courier">=
&lt;+&gt;</font> or <font face=3D"Courier">[[+]]</font>.</div><div><br></di=
v><div>Given this level of metaprocessing, might as well use tuple (with se=
quence concatenation semantics) instead of pair :P</div></div><br></body></=
html>

<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 />

--Apple-Mail=_3B9D816D-07D8-435E-A210-F25D0B8B2AE8--

.


Author: Stack Machine <stackmachine@hotmail.com>
Date: Tue, 22 Jul 2014 01:40:57 -0700 (PDT)
Raw View
------=_Part_56_35934432.1406018457655
Content-Type: text/plain; charset=UTF-8

I would call it user defined declarators instead. Also, I can see some
valid use cases for this idea. How about some tuples? Or some maps? What
about std::optional?
{int, double} tuple = {42, 3.14};
[string -> int] map = {{"hello", 5}, {"world", 10}};
int? x = nullopt;
However, i wouldn't know how to define rules for parsing this. We'd need
parenthesis-kind declarators that depend on the operators between types. If
anyone has an idea how to do this properly, please let me know. I'm trying
to get such a feature into my own language and couldn't come up with good
parsing rules.

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_56_35934432.1406018457655
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I would call it user defined declarators instead. Also, I =
can see some valid use cases for this idea. How about some tuples? Or some =
maps? What about std::optional?<br><div class=3D"prettyprint" style=3D"back=
ground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-=
style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pre=
ttyprint"><div class=3D"subprettyprint"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">double</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> tuple </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{</span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">42</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">3.=
14</span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">string</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">-&gt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">]</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> map </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">{{</span><span style=
=3D"color: #080;" class=3D"styled-by-prettify">"hello"</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" cla=
ss=3D"styled-by-prettify">5</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">},</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
{</span><span style=3D"color: #080;" class=3D"styled-by-prettify">"world"</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">10</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">}};</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">?</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> x </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> nul=
lopt</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></di=
v></code></div>However, i wouldn't know how to define rules for parsing thi=
s. We'd need parenthesis-kind declarators that depend on the operators betw=
een types. If anyone has an idea how to do this properly, please let me kno=
w. I'm trying to get such a feature into my own language and couldn't come =
up with good parsing rules.<br></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_56_35934432.1406018457655--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Tue, 22 Jul 2014 19:37:54 +0200
Raw View
Le 12/07/14 01:31, Andrew Tomazos a =C3=A9crit :
> Here is a fun little idea:
>
>     template<typename T1, typename T2>
>     using operator+ =3D std::pair<T1, T2>;
>
>     struct A{};  struct B {};
>
>     using C =3D A + B;
>
>     static_assert(std::is_same_v<C, std::pair<A,B>>); // ok
>
>     int + float x =3D {42, 2.0}; // lol
>
In type theory this corresponds to the product type so maybe it is best=20
to use A * B

>     template<typename T1, typename T2>
>     using operator| =3D boost::variant<T1, T2>;
>
>     template<typename T1, typename... Ts>
>     using operator| <T1, boost::variant<Ts...>> =3D boost::variant<T1,=20
> Ts...>;
>
>     struct X{}; struct Y{}; struct Z{}
>
>     using W =3D X | Y | Z;
>
>     static_assert(std::is_same_v<W, boost::variant<X,Y,Z>>);
>
and this to the sum type, and so to be coherent A + B could be more=20
appropriated.

Just my 2cts,
Vicente

--=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/.

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 22 Jul 2014 11:30:32 -0700
Raw View
On Tuesday 22 July 2014 01:40:57 Stack Machine wrote:
> {int, double} tuple = {42, 3.14};

struct { int i; double d; } tuple = { 42, 3.14 };

Do we need another syntax?
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Johannes Schaub <schaub.johannes@googlemail.com>
Date: Tue, 22 Jul 2014 20:32:43 +0200
Raw View
2014-07-22 20:30 GMT+02:00 Thiago Macieira <thiago@macieira.org>:
> On Tuesday 22 July 2014 01:40:57 Stack Machine wrote:
>> {int, double} tuple = {42, 3.14};
>
> struct { int i; double d; } tuple = { 42, 3.14 };
>
> Do we need another syntax?

// incompatible types in initialization: unnamed-tuple vs unnamed-tuple1
struct { int i; double d; } tuple1 = tuple;

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.