Topic: Comments on N3584 Wording for Addressing Tuples by Type


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Wed, 15 May 2013 07:40:51 +0200
Raw View
This is a multi-part message in MIME format.
--------------090903020207030408080404
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi,

I was wondering if instead of using the get<type>(tpl) form

|tuple<string, string, int> t("foo", "bar", 7);
int i = get<int>(t);// i == 7
int j = get<2>(t); // Equivalent to the above: j == 7
string s = get<string>(t);

we can not use the conversion operator type(tpl)

| |tuple<string, string, int> t("foo", "bar", 7);
|||int i = int(t);// i == 7
|||||int i(t);// i == 7
||int j = get<2>(t); // Equivalent to the above: j == 7
||string s = string(t);|
|string s(t);|

I'm using this kind of conversion on a year_month_day tuple like class
to access the year, month and day members, and I find it much more
intuitive than the get<type>() syntax.

I would reserve the get<type>() syntax for named tuples

struct f1{};
struct f2{};
struct f3{};
|||tuple<tagged<string, f1>, tagged<string, f2>, tagged<int, f3>>
t("foo", "bar", 7); |
|int i = get<f2>(t);// i == 7
|
Best,
Vicente

--

---
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/?hl=en.



--------------090903020207030408080404
Content-Type: text/html; charset=ISO-8859-1

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi,<br>
    <br>
    I was wondering if instead of using the get&lt;type&gt;(tpl) form<br>
    <br>
    <meta http-equiv="content-type" content="text/html;
      charset=ISO-8859-1">
    <code>tuple&lt;string, string, int&gt; t("foo", "bar", 7);
      <br>
      int i = get&lt;int&gt;(t);<span class="comment"> // i == 7</span>
      <br>
      int j = get&lt;2&gt;(t); <span class="comment"> // Equivalent to
        the above: j == 7</span>
      <br>
      string s = get&lt;string&gt;(t);<span class="comment"> <br>
        <br>
        we can not use the conversion operator type(tpl)<br>
        <br>
      </span></code>
    <meta http-equiv="content-type" content="text/html;
      charset=ISO-8859-1">
    <code>tuple&lt;string, string, int&gt; t("foo", "bar", 7);
      <br>
    </code><code><code>int i = int(t);<span class="comment"> // i == 7</span>
        <br>
      </code></code><code><code><code>int i(t);<span class="comment"> //
            i == 7</span> <br>
        </code></code>int j = get&lt;2&gt;(t); <span class="comment">
        // Equivalent to the above: j == 7</span>
      <br>
    </code><code>string s = string(t);<span class="comment"> </span></code><br>
    <code>string s(t);<span class="comment"> </span></code><br>
    <br>
    I'm using this kind of conversion on a year_month_day tuple like
    class to access the year, month and day members, and I find it much
    more intuitive than the get&lt;type&gt;() syntax.<br>
    <br>
    I would reserve the get&lt;type&gt;() syntax for named tuples<br>
    <br>
    struct f1{};<br>
    struct f2{};<br>
    struct f3{};<br>
    <code></code><code>tuple&lt;tagged&lt;string, f1&gt;,
      tagged&lt;string, f2&gt;, tagged&lt;int, f3&gt;&gt; t("foo",
      "bar", 7);
    </code><br>
    <code>int i = get&lt;f2&gt;(t);<span class="comment"> // i == 7</span>
      <br>
    </code><br>
    Best,<br>
    Vicente<br>
  </body>
</html>

<p></p>

-- <br />
&nbsp;<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 email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en">http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en</a>.<br />
&nbsp;<br />
&nbsp;<br />

--------------090903020207030408080404--

.