<div dir="ltr">I'd suggest considering what it'll look like when we're migrating to concepts in C++20.<div><br></div><div>Here's an example for our bitwise_cast:</div><div><a href="https://github.com/jfbastien/bit_cast/blob/master/bit_cast.h#L10">https://github.com/jfbastien/bit_cast/blob/master/bit_cast.h#L10</a><br></div><div><br></div><div>Notice the 3 ways to enable. There's also the option of using enable_if on the return value, or as a defaulted function parameter, but I'm not a huge fan of either.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 22, 2017 at 9:13 PM, Chris Dumez <span dir="ltr"><<a href="mailto:cdumez@apple.com" target="_blank">cdumez@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">I personally prefer std::enable_if<>. For e.g.<div><br></div><div>template<typename T, class = <wbr>typename std::enable_if<std::<wbr>is_same<T, int>::value></div><div>Class Foo { }</div><div><br></div><div>I don’t like that something inside the body of a class / function would cause a template to be enabled or not.</div><div><br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div>--</div><div><span style="font-size:13px"> </span>Chris Dumez</div></div></div></div><br class="m_7366142924721886508Apple-interchange-newline"></div><br class="m_7366142924721886508Apple-interchange-newline"><br class="m_7366142924721886508Apple-interchange-newline">
</div><div><div class="h5">
<div><br><blockquote type="cite"><div>On Aug 22, 2017, at 8:34 PM, Keith Miller <<a href="mailto:keith_miller@apple.com" target="_blank">keith_miller@apple.com</a>> wrote:</div><br class="m_7366142924721886508Apple-interchange-newline"><div><div>Hello fellow WebKittens,<br><br>I’ve noticed over time that we don’t have standard way that we enable versions of template functions/classes (flasses?). For the most part it seems that people use std::enable_if, although, it seems like it is attached to every possible place in the function/class.<br><br>I propose that we choose a standard way to conditionally enable a template.<br><br>There are a ton of options; my personal favorite is to add the following macro:<br><br>#define ENABLE_TEMPLATE_IF(condition) static_assert(condition, “template disabled”)<br><br>Then have every function do:<br><br>template<typename T><br>void foo(…)<br>{<br>    ENABLE_TEMPLATE_IF(std::is_<wbr>same<T, int>::value);<br>    …<br>}<br><br>And classes:<br><br>template<typename T><br>class Foo {<br>    ENABLE_TEMPLATE_IF(std::is_<wbr>same<T, int>::value);<br>};<br><br>I like this proposal because it doesn’t obstruct the signature/declaration of the function/class but it’s still obvious when the class is enabled. Obviously, I think we should require that this macro is the first line of the function or class for visibility. Does anyone else have thoughts or ideas?<br><br>Cheers,<br>Keith<br><br>P.S. in case you are wondering why this macro works (ugh C++), it’s because if there is any compile time error in a template it cannot be selected as the final candidate. In my examples, if you provided a type other than int foo/Foo could not be selected because the static_assert condition would be false, which is a compile error.<br>______________________________<wbr>_________________<br>webkit-dev mailing list<br><a href="mailto:webkit-dev@lists.webkit.org" target="_blank">webkit-dev@lists.webkit.org</a><br><a href="https://lists.webkit.org/mailman/listinfo/webkit-dev" target="_blank">https://lists.webkit.org/<wbr>mailman/listinfo/webkit-dev</a><br></div></div></blockquote></div><br></div></div></div></div><br>______________________________<wbr>_________________<br>
webkit-dev mailing list<br>
<a href="mailto:webkit-dev@lists.webkit.org">webkit-dev@lists.webkit.org</a><br>
<a href="https://lists.webkit.org/mailman/listinfo/webkit-dev" rel="noreferrer" target="_blank">https://lists.webkit.org/<wbr>mailman/listinfo/webkit-dev</a><br>
<br></blockquote></div><br></div>