<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	
	>
<channel>
	<title>
	Comments on: Functors are not dead: the double functor trick	</title>
	<atom:link href="https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Mon, 18 Sep 2017 07:11:41 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.4</generator>
	<item>
		<title>
		By: Tony Lewis		</title>
		<link>https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-179</link>

		<dc:creator><![CDATA[Tony Lewis]]></dc:creator>
		<pubDate>Fri, 17 Mar 2017 12:01:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=635#comment-179</guid>

					<description><![CDATA[Nice post. Thanks.

Whilst you&#039;re on the theme of comparing elements with a value of a different type, it might be worth mentioning the projection functions adopted in the ongoing Ranges work by Eric Niebler and others. In these sorts of contexts, the projections can often make things substantially cleaner and more expressive than with the std algorithms, eg you could sort your vector of Employees by ID with something like:

sort(
  employees,
  less{},
  [] (const Employee &#038;e){ return e.getId(); }
);

See:
 * Eric&#039;s range-v3 library: https://github.com/ericniebler/range-v3
 * eg start of cppreference documentation of ranges proposal for the Standard http://en.cppreference.com/w/cpp/experimental/ranges/algorithm/sort]]></description>
			<content:encoded><![CDATA[<p>Nice post. Thanks.</p>
<p>Whilst you&#8217;re on the theme of comparing elements with a value of a different type, it might be worth mentioning the projection functions adopted in the ongoing Ranges work by Eric Niebler and others. In these sorts of contexts, the projections can often make things substantially cleaner and more expressive than with the std algorithms, eg you could sort your vector of Employees by ID with something like:</p>
<p>sort(<br />
  employees,<br />
  less{},<br />
  [] (const Employee &amp;e){ return e.getId(); }<br />
);</p>
<p>See:<br />
 * Eric&#8217;s range-v3 library: <a href="https://github.com/ericniebler/range-v3" rel="nofollow ugc">https://github.com/ericniebler/range-v3</a><br />
 * eg start of cppreference documentation of ranges proposal for the Standard <a href="http://en.cppreference.com/w/cpp/experimental/ranges/algorithm/sort" rel="nofollow ugc">http://en.cppreference.com/w/cpp/experimental/ranges/algorithm/sort</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Vladislav Kaplan		</title>
		<link>https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-169</link>

		<dc:creator><![CDATA[Vladislav Kaplan]]></dc:creator>
		<pubDate>Tue, 14 Mar 2017 10:24:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=635#comment-169</guid>

					<description><![CDATA[Thank you for the article]]></description>
			<content:encoded><![CDATA[<p>Thank you for the article</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-162</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Sun, 12 Mar 2017 21:12:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=635#comment-162</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-148&quot;&gt;Arne Mertz&lt;/a&gt;.

Thanks Arne for taking the time to point this out.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-148">Arne Mertz</a>.</p>
<p>Thanks Arne for taking the time to point this out.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-163</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Sun, 12 Mar 2017 21:12:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=635#comment-163</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-156&quot;&gt;Yehezkel&lt;/a&gt;.

This is interesting indeed! Thanks Yehezkel for sharing.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-156">Yehezkel</a>.</p>
<p>This is interesting indeed! Thanks Yehezkel for sharing.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-161</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Sun, 12 Mar 2017 21:11:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=635#comment-161</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-149&quot;&gt;DimanNe DimanNe&lt;/a&gt;.

Thanks for pointing this out, I&#039;ve included this info in the body of the post.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-149">DimanNe DimanNe</a>.</p>
<p>Thanks for pointing this out, I&#8217;ve included this info in the body of the post.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yehezkel		</title>
		<link>https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-156</link>

		<dc:creator><![CDATA[Yehezkel]]></dc:creator>
		<pubDate>Sun, 12 Mar 2017 18:59:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=635#comment-156</guid>

					<description><![CDATA[With C++17 &quot;constexpr if&quot; you can do something like:
auto comparator = [](auto const&#038; a, auto const&#038; b) {
    if constexpr (typeid(a) == typeid(int) &#038;&#038; typeid(b) == typeid(Employee))
         return a &#060; b.getReference();
    else if constexpr (typeid(a) == typeid(Employee) &#038;&#038; typeid(b) == typeid(int))
         return a.getReference() &#060; b;
    else
        static_assert(false, &#034;Unsupported argument types&#034;);
};

:)]]></description>
			<content:encoded><![CDATA[<p>With C++17 &#8220;constexpr if&#8221; you can do something like:<br />
auto comparator = [](auto const&amp; a, auto const&amp; b) {<br />
    if constexpr (typeid(a) == typeid(int) &amp;&amp; typeid(b) == typeid(Employee))<br />
         return a &lt; b.getReference();<br />
    else if constexpr (typeid(a) == typeid(Employee) &amp;&amp; typeid(b) == typeid(int))<br />
         return a.getReference() &lt; b;<br />
    else<br />
        static_assert(false, &quot;Unsupported argument types&quot;);<br />
};</p>
<p>🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: DimanNe DimanNe		</title>
		<link>https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-149</link>

		<dc:creator><![CDATA[DimanNe DimanNe]]></dc:creator>
		<pubDate>Fri, 10 Mar 2017 16:40:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=635#comment-149</guid>

					<description><![CDATA[Why can&#039;t you just inherit from two lambdas?
auto Lambda1 = [](std::string s) { return s; };
auto Lambda2 = [](int )          { return &quot;int&quot;; };
auto MultiLambda = MakeMultiLambda(Lambda1, Lambda2, Lambda3);
std::cout &#060;&#060; MultiLambda(3) &#060;&#060; std::endl;
std::cout &#060;&#060; MultiLambda(&#034;qwer&#034;) &#060;&#060; std::endl;

Search for &#034;Lambda overloading&#034; here - https://sites.google.com/view/compthoughts/c]]></description>
			<content:encoded><![CDATA[<p>Why can&#8217;t you just inherit from two lambdas?<br />
auto Lambda1 = [](std::string s) { return s; };<br />
auto Lambda2 = [](int )          { return &#8220;int&#8221;; };<br />
auto MultiLambda = MakeMultiLambda(Lambda1, Lambda2, Lambda3);<br />
std::cout &lt;&lt; MultiLambda(3) &lt;&lt; std::endl;<br />
std::cout &lt;&lt; MultiLambda(&quot;qwer&quot;) &lt;&lt; std::endl;</p>
<p>Search for &quot;Lambda overloading&quot; here &#8211; <a href="https://sites.google.com/view/compthoughts/c" rel="nofollow ugc">https://sites.google.com/view/compthoughts/c</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Arne Mertz		</title>
		<link>https://www.fluentcpp.com/2017/03/09/functors-are-not-dead-the-double-functor-trick/#comment-148</link>

		<dc:creator><![CDATA[Arne Mertz]]></dc:creator>
		<pubDate>Fri, 10 Mar 2017 14:02:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=635#comment-148</guid>

					<description><![CDATA[Hi Jonathan, nice article!
There is a proposal (P0051) for a generalized overload function that combines function objects like lambdas. With that, your &quot;CompareWithReference&quot; class could be written on the fly as 

    overload (
        [](Employee const&#038; employee, int reference) { return employee.getReference() &#060; reference; },
        [](int reference, Employee const&#038; employee) { return reference &#060; employee.getReference(); }
    )

In this case, it&#039;s not as nice to read as the named function object, but in some cases (e.g. std::visit) it comes handy. I have included an example and a simplified implementation of overload for lambdas here: http://foonathan.net/blog/2017/03/01/tuple-iterator.html

In general I agree with you, however: Lambdas are not the silver bullet people are looking for.]]></description>
			<content:encoded><![CDATA[<p>Hi Jonathan, nice article!<br />
There is a proposal (P0051) for a generalized overload function that combines function objects like lambdas. With that, your &#8220;CompareWithReference&#8221; class could be written on the fly as </p>
<p>    overload (<br />
        [](Employee const&amp; employee, int reference) { return employee.getReference() &lt; reference; },<br />
        [](int reference, Employee const&amp; employee) { return reference &lt; employee.getReference(); }<br />
    )</p>
<p>In this case, it&#039;s not as nice to read as the named function object, but in some cases (e.g. std::visit) it comes handy. I have included an example and a simplified implementation of overload for lambdas here: <a href="http://foonathan.net/blog/2017/03/01/tuple-iterator.html" rel="nofollow ugc">http://foonathan.net/blog/2017/03/01/tuple-iterator.html</a></p>
<p>In general I agree with you, however: Lambdas are not the silver bullet people are looking for.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
