Boost C++ Libraries: Ticket #3446: [boost] [fusion] transform does not return a mutable view https://svn.boost.org/trac10/ticket/3446 <p> Based on the documentation (and my own experience), it doesn't appear that transform will return a mutable transform_view, since transform receives its sequence argument always by const reference. Is this intentional, or an oversight? It seems like there's no loss in providing 2 overloads of transform, one accepting a const reference and one accepting a non-const reference. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3446 Trac 1.4.3 Joel de Guzman Mon, 14 Sep 2009 05:19:57 GMT <link>https://svn.boost.org/trac10/ticket/3446#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:1</guid> <description> <p> That is by design. A transform_view is lazily evaluated. You'd want to assign back to the original container if you want it mutated. The effect and performance is the same. </p> <p> Do you have some code? I can probably recommend a way to do what you want. </p> </description> <category>Ticket</category> </item> <item> <author>Jeffrey Hellrung <jhellrung@…></author> <pubDate>Mon, 14 Sep 2009 05:37:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:2</guid> <description> <p> I was trying to do something along the lines of </p> <p> copy(source, transform(dest, project()) </p> <p> where source and dest are Boost.Fusion conforming sequences (but not necessarily the data structures from the Boost.Fusion library); copy is a function I wrote that operates on Boost.Fusion sequences (with the expected semantics; I couldn't find something in Boost.Fusion that would accomplish the same thing); and project is a function object returning a reference to a particular member variable of each element of dest. </p> <p> What do you think? </p> <p> Thanks, </p> <ul><li>Jeff </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Mon, 14 Sep 2009 06:03:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:3</guid> <description> <p> copy is just assign: </p> <blockquote> <p> dest = src </p> </blockquote> <p> It works with any src and dest type as long as src is a fusion sequence and dest is a fusion container with the same element types and same number of elements. </p> <p> a mutating transform is just: </p> <blockquote> <p> for_each(s, f) </p> </blockquote> <p> So, I dont see why your code can't be rewritten as: </p> <blockquote> <p> dest = src; for_each(dest, project()); </p> </blockquote> <p> What am I missing? </p> </description> <category>Ticket</category> </item> <item> <author>Jeffrey Hellrung <jhellrung@…></author> <pubDate>Mon, 14 Sep 2009 06:31:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:4</guid> <description> <p> First, I wasn't aware that assignment of a Boost.Fusion sequence to, e.g., a boost::array would work? I admit I've never tried it... </p> <p> Second, think of project as something like </p> <pre class="wiki">project { template&lt; class First, class Second &gt; First&amp; operator()(std::pair&lt; First, Second &gt;&amp; x) const { return x.first; } } </pre><p> I essentially want something to the effect of </p> <pre class="wiki">for i = 0, ..., size dest[i].member_var = source[i] </pre><ul><li>Jeff </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Mon, 14 Sep 2009 06:45:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:5</guid> <description> <blockquote class="citation"> <p> First, I wasn't aware that assignment of a Boost.Fusion sequence to, e.g., a boost::array would work? I admit I've never tried it... </p> </blockquote> <p> Ah indeed it won't. boost::array is not a fusion container. So you have a good use case for copy indeed. I suggest you polish it, provide docs, and I'd gladly add that to the library. </p> <p> Now, back to what you want. It seems that you don't need in-place mutation at all! </p> <blockquote> <p> copy(transform(src, project()), dest); </p> </blockquote> <p> where project returns src[i].member_var for each member. This is as fast as you expect it to be since transform is lazily evaluated. </p> <p> Thoughts? </p> </description> <category>Ticket</category> </item> <item> <author>Jeffrey Hellrung <jhellrung@…></author> <pubDate>Mon, 14 Sep 2009 06:56:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:6</guid> <description> <p> Re copy: Sounds good, although I'd have to familiarize myself with the boost quickbook (?) documentation creator thingy. Any helpful suggestions? </p> <p> The problem your suggestion is it's backwards from what I want: </p> <p> copy(transform(src, project()), dest) &lt;=&gt; dest[i] = src[i].member_var </p> <p> whereas I'm aiming toward </p> <p> copy(src, transform(dest, project())) &lt;=&gt; dest[i].member_var = src[i] </p> <ul><li>Jeff </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Mon, 14 Sep 2009 07:10:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:7</guid> <description> <p> Ok, I'm convinced. You have a valid use case. Care to submit a patch + docs? I'd also want to have your copy algo in. As for qbk, just copy one of the qbk files and tweak. That's the easiest path. I'll do the rest. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Mon, 14 Sep 2009 07:11:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:8</guid> <description> <p> Oh, please add tests too, if you will. </p> <p> THANKS! </p> </description> <category>Ticket</category> </item> <item> <author>Jeffrey Hellrung <jhellrung@…></author> <pubDate>Mon, 14 Sep 2009 07:24:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:9</guid> <description> <p> Okay, I'll try my hand at it. Could be a week or two, though ;) </p> <p> Also, there's another Fusion addition I use that I've found useful: as_mpl_vector. It is strictly a metafunction which converts a Boost.Fusion conforming sequence into a Boost.MPL vector. I know all "built-in" Fusion sequences are already MPL sequences (with the appropriate include), but it didn't seem like adapted Fusion sequences also had this property, hence the need arose. I've occasionally needed this to add compile-time checks or type-computations on a Boost.Fusion parameter to a function. Let me know if this also sounds like something that could be added, or if you need an example use case. </p> <ul><li>Jeff </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Mon, 14 Sep 2009 08:47:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:10</guid> <description> <p> Sounds good, but why stop at vector? It would make sense to have all: vector/list/map/set. ;-) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Christopher Schmidt</dc:creator> <pubDate>Mon, 21 Sep 2009 17:25:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:11</guid> <description> <p> I implemented that very feature in my c++0x port of fusion. Feel free to copy&amp;paste the relevant changes. You can find the code in the sandbox (/sandbox/SOC/2009/fusion) </p> <p> What particular property/feature are you missing when working with MPL-fied fusion sequences? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Christopher Schmidt</dc:creator> <pubDate>Mon, 21 Sep 2009 17:27:06 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/3446#comment:12 https://svn.boost.org/trac10/ticket/3446#comment:12 <ul> <li><strong>cc</strong> <span class="trac-author">Christopher Schmidt</span> added </li> </ul> Ticket Jeffrey Hellrung <jhellrung@…> Mon, 21 Sep 2009 18:13:33 GMT <link>https://svn.boost.org/trac10/ticket/3446#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:13</guid> <description> <p> I'm not sure I understand your question, but here's an attempt at an answer ;) </p> <p> If you have a function, e.g., that takes any Boost.Fusion conforming sequence as a parameter, and whose return type or intermediate types must be deduced from the types in the sequence, it is often convenient to use the Boost.MPL metafunctions on this type sequence. However, although all the containers in the Boost.Fusion library are (conveniently, via an include) conforming MPL sequences, a Boost.Fusion conforming sequence is not generally required to be a Boost.MPL conforming sequence (think boost::array), so the use of Boost.MPL metafunctions on the type sequence generally requires a conversion to a Boost.MPL vector (or other Boost.MPL sequence). </p> <p> Thanks for the code reference. I still need to find some downtime to add these proposals to the current Boost.Fusion version :/ </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Christopher Schmidt</dc:creator> <pubDate>Mon, 21 Sep 2009 18:40:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3446#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3446#comment:14</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3446#comment:13" title="Comment 13">Jeffrey Hellrung &lt;jhellrung@…&gt;</a>: I got it. Sorry, I just came back from work when I wrote the question above - it would have been clear in the first place if I'd mulled it over once more. </p> </description> <category>Ticket</category> </item> </channel> </rss>