<?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: How to Make SFINAE Pretty &#8211; Part 2: the Hidden Beauty of SFINAE	</title>
	<atom:link href="https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Wed, 24 Jul 2019 04:15:35 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.3</generator>
	<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1359</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Thu, 04 Oct 2018 21:43:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2769#comment-1359</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1314&quot;&gt;Josh Howe&lt;/a&gt;.

Indeed, thanks Josh, this is fixed now.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1314">Josh Howe</a>.</p>
<p>Indeed, thanks Josh, this is fixed now.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Josh Howe		</title>
		<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1314</link>

		<dc:creator><![CDATA[Josh Howe]]></dc:creator>
		<pubDate>Thu, 20 Sep 2018 21:09:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2769#comment-1314</guid>

					<description><![CDATA[Small typo: this line in the enable_if_t definition:

    template

should be 

    template

(i.e., &quot;typename&quot; instead of &quot;template&quot;).]]></description>
			<content:encoded><![CDATA[<p>Small typo: this line in the enable_if_t definition:</p>
<p>    template</p>
<p>should be </p>
<p>    template</p>
<p>(i.e., &#8220;typename&#8221; instead of &#8220;template&#8221;).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Miguel Raggi		</title>
		<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1059</link>

		<dc:creator><![CDATA[Miguel Raggi]]></dc:creator>
		<pubDate>Tue, 12 Jun 2018 18:26:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2769#comment-1059</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1058&quot;&gt;Jonathan Boccara&lt;/a&gt;.

Sure, that would work in C++17, but my target right now is C++14. I hope to be able to &quot;migrate&quot; soon.

Is there any way to insert nicely formatted source code in Disqus? I just noticed it changed some of my T_ to t_ for some reason!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1058">Jonathan Boccara</a>.</p>
<p>Sure, that would work in C++17, but my target right now is C++14. I hope to be able to &#8220;migrate&#8221; soon.</p>
<p>Is there any way to insert nicely formatted source code in Disqus? I just noticed it changed some of my T_ to t_ for some reason!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1058</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Tue, 12 Jun 2018 17:06:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2769#comment-1058</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1050&quot;&gt;Miguel Raggi&lt;/a&gt;.

I see your point, interesting! Thanks for sharing.
Did you consider trying to remove the makeMyClass function, by using C++17 template argument deduction for class constructors?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1050">Miguel Raggi</a>.</p>
<p>I see your point, interesting! Thanks for sharing.<br />
Did you consider trying to remove the makeMyClass function, by using C++17 template argument deduction for class constructors?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Miguel Raggi		</title>
		<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1050</link>

		<dc:creator><![CDATA[Miguel Raggi]]></dc:creator>
		<pubDate>Fri, 08 Jun 2018 11:28:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2769#comment-1050</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1047&quot;&gt;Jonathan Boccara&lt;/a&gt;.

I would like to avoid copy construction at all cost. So I want a member variable that, depending on the constructor, is either a string or a string&#038;.

After many hours searching and experimenting, I think I&#039;ve found the answer: universal references. I never understood them until now! Apparently, when using T&#038;&#038;, if T is used for template deduction, it becomes either an lvalue *reference* or an rvalue. I think this was exactly their point.

For example:
struct Large
{
    Large() = default;
    Large(const Large&#038;) { cout &#060;&#060; &#034;copy ctor&#034; &#060;&#060; endl; };
    Large(Large&#038;&#038;) { cout &#060;&#060; &#034;move ctor&#034; &#060;&#060; endl; };
};

template
class MyClass
{
public:
    template 
    MyClass(T_&#038;&#038; x) : x_{std::forward(x)} {}
    
    T x_;
};

template 
auto makeMyClass(T&#038;&#038; f) -&#062; MyClass
{
    return {std::forward(f)};
}

Large get_Large()
{
    return Large();
}


int main()
{
    cout &#060;&#060; &#034;Should call move ctor:&#034; &#060;&#060; endl;
    auto A = makeMyClass(get_Large());
    
    cout &#060;&#060; &#034;nShould not call either copy ctor or move dtor:&#034; &#060;&#060; endl;
    Large b;
    auto B = makeMyClass(b);

    return 0;
}

So the above NEVER calls a copy ctor of Large, which is what I wanted to avoid. And it&#039;s fine in both cases: in the first, it moves from get_Large(), and in the second it just stores a reference to b, but that&#039;s fine, since b is alive an well (it&#039;s an lvalue) and won&#039;t be destructed until B is.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1047">Jonathan Boccara</a>.</p>
<p>I would like to avoid copy construction at all cost. So I want a member variable that, depending on the constructor, is either a string or a string&amp;.</p>
<p>After many hours searching and experimenting, I think I&#8217;ve found the answer: universal references. I never understood them until now! Apparently, when using T&amp;&amp;, if T is used for template deduction, it becomes either an lvalue *reference* or an rvalue. I think this was exactly their point.</p>
<p>For example:<br />
struct Large<br />
{<br />
    Large() = default;<br />
    Large(const Large&amp;) { cout &lt;&lt; &quot;copy ctor&quot; &lt;&lt; endl; };<br />
    Large(Large&amp;&amp;) { cout &lt;&lt; &quot;move ctor&quot; &lt;&lt; endl; };<br />
};</p>
<p>template<br />
class MyClass<br />
{<br />
public:<br />
    template<br />
    MyClass(T_&amp;&amp; x) : x_{std::forward(x)} {}</p>
<p>    T x_;<br />
};</p>
<p>template<br />
auto makeMyClass(T&amp;&amp; f) -&gt; MyClass<br />
{<br />
    return {std::forward(f)};<br />
}</p>
<p>Large get_Large()<br />
{<br />
    return Large();<br />
}</p>
<p>int main()<br />
{<br />
    cout &lt;&lt; &quot;Should call move ctor:&quot; &lt;&lt; endl;<br />
    auto A = makeMyClass(get_Large());</p>
<p>    cout &lt;&lt; &quot;nShould not call either copy ctor or move dtor:&quot; &lt;&lt; endl;<br />
    Large b;<br />
    auto B = makeMyClass(b);</p>
<p>    return 0;<br />
}</p>
<p>So the above NEVER calls a copy ctor of Large, which is what I wanted to avoid. And it&#039;s fine in both cases: in the first, it moves from get_Large(), and in the second it just stores a reference to b, but that&#039;s fine, since b is alive an well (it&#039;s an lvalue) and won&#039;t be destructed until B is.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1047</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Fri, 08 Jun 2018 06:28:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2769#comment-1047</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1045&quot;&gt;Miguel Raggi&lt;/a&gt;.

How would you see the members of MyClass? A std::string an a std::string const&#038;, or something like a variant?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1045">Miguel Raggi</a>.</p>
<p>How would you see the members of MyClass? A std::string an a std::string const&amp;, or something like a variant?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Miguel Raggi		</title>
		<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1045</link>

		<dc:creator><![CDATA[Miguel Raggi]]></dc:creator>
		<pubDate>Thu, 07 Jun 2018 11:59:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2769#comment-1045</guid>

					<description><![CDATA[One question:

Suppose I wanted to save, inside MyClass, either a copy if T is an rvalue (and move from it!), or just a reference if I&#039;m passed an lvalue (since I know it still exists).

For example:

MyClass A(get_string()) &#060;- moves into a member variable of type std::string
std::string s = &#034;hello world&#034;;
MyClass A(s) &#060;- copies into a member variable of type std::string const&#038;]]></description>
			<content:encoded><![CDATA[<p>One question:</p>
<p>Suppose I wanted to save, inside MyClass, either a copy if T is an rvalue (and move from it!), or just a reference if I&#8217;m passed an lvalue (since I know it still exists).</p>
<p>For example:</p>
<p>MyClass A(get_string()) &lt;- moves into a member variable of type std::string<br />
std::string s = &quot;hello world&quot;;<br />
MyClass A(s) &lt;- copies into a member variable of type std::string const&amp;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Angus McIonnach		</title>
		<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1010</link>

		<dc:creator><![CDATA[Angus McIonnach]]></dc:creator>
		<pubDate>Tue, 22 May 2018 11:33:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2769#comment-1010</guid>

					<description><![CDATA[Looking forward to Part 3, &quot;okay, okay, now we&#039;re going to make SFINAE pretty, finally&quot;.]]></description>
			<content:encoded><![CDATA[<p>Looking forward to Part 3, &#8220;okay, okay, now we&#8217;re going to make SFINAE pretty, finally&#8221;.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Liquidify		</title>
		<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-1003</link>

		<dc:creator><![CDATA[Liquidify]]></dc:creator>
		<pubDate>Sat, 19 May 2018 06:36:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2769#comment-1003</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-996&quot;&gt;John Melas&lt;/a&gt;.

Is there a way to do the same without a macro?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-996">John Melas</a>.</p>
<p>Is there a way to do the same without a macro?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: John Melas		</title>
		<link>https://www.fluentcpp.com/2018/05/18/make-sfinae-pretty-2-hidden-beauty-sfinae/#comment-996</link>

		<dc:creator><![CDATA[John Melas]]></dc:creator>
		<pubDate>Fri, 18 May 2018 06:32:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2769#comment-996</guid>

					<description><![CDATA[Great article Jonathan! Thanks! 
Perhaps it should be noted that SFINAE could become prettier also with a macro ie
#define REQUIRES(...) 
	typename = std::enable_if_t]]></description>
			<content:encoded><![CDATA[<p>Great article Jonathan! Thanks!<br />
Perhaps it should be noted that SFINAE could become prettier also with a macro ie<br />
#define REQUIRES(&#8230;)<br />
	typename = std::enable_if_t</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
