<br><br><div class="gmail_quote">On Sun, Feb 19, 2012 at 5:48 PM, Robert Ramey <span dir="ltr"><<a href="mailto:ramey@rrsd.com">ramey@rrsd.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <u></u> <div bgcolor="#ffffff"><div class="im"> <div>Ovanes Markarian wrote:<br>> On Fri, Feb 17, 2012 at 9:40 PM, Robert Ramey <<a href="mailto:ramey@rrsd.com" target="_blank">ramey@rrsd.com</a>> wrote:<br>> <br>> [...]<br>> <br>> Andre Alex... gave a talk at "Going Native"� proposing<br>> a "static if" for this case.� But I don't see the necessity for<br>> for this since I would assume that the compiler<br>> just optimises away the "dead" code.� I've compiled<br>> the above and it seems to do what I want but<br>> still I wonder.<br>> <br>> <br>> Robert, I see Andrey's proposal aimed to replace the enable_if which<br>> is based on SFINAE and greatly simplify the metaprogramming<br>> machinery. The code you present if fine and it might be optimized<br>> away by the compiler, but it might produce compilation errors, since<br>> all runtime branches of if-statement must be compilable without<br>> errors. SFINAE aimes to work around it, like we can enable some<br>> special treatment if the provided code "would compile" without<br>> errors.�</div> <div>�</div> </div><div><font face="Arial">Basically this example is the first slide in Andrei's talk.� The purpose</font></div> <div><font face="Arial">was to introduce a use case for the need for "static if".� To my mind</font></div> <div><font face="Arial">it failed in its purpose since a "normal if" already does that.� It's even</font></div> <div><font face="Arial">worse - Andrei ruminated on the question as to what should be done</font></div> <div><font face="Arial">with the "dead" branch.� i.e. should it be skipped entirely or actually</font></div> <div><font face="Arial">compiled - he left that question open.� It seemed to me that for this</font></div> <div><font face="Arial">case, the whole question could be addressed by adding language</font></div> <div><font face="Arial">to the standard that a compiler should elminate code for which</font></div> <div><font face="Arial">it can be determined at compile time will never be run.�</font></div></div></blockquote><div>[...]</div><div>Robert, somehow I do not get your proposal. How do you consider an if-branch, which is not going to compile, i.e. compilation error. Do you propose, to ignore that branch and just state: "OK, if there is a compilation error, that must be eliminated without any errors to the end-user". I don't think this can work. Therefore there should be a special language construct, which states: "if there is a compilation error, than it is safe to be ignored during the compilation"</div> <div><br></div><div>[...]</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#ffffff"><div><div class="im"> <div><font face="Arial"></font><font face="Arial"></font><br>> On the other hand using static if we might inspect the exposed type<br>> system of some type T. Let's say we would like to unify some<br>> different types using a traits class. Out traits class should expose<br>> value_type of the inspected type (say we have a boost::shared_ptr and<br>> std::vector as input). boost::shared_ptr contains a typedef of<br>> underlying type which is named element_type and std::vector names the<br>> underlying type value_type. Out traits type should homogenize these<br>> two types and provide a value_type member, which contains the<br>> underlying type of either shared_ptr or std::vector. It can be easily<br>> "calculated/specialized/inspected" with static if construct. How are<br>> you going to solve this problem with the runtime if without using<br>> enable_if , overloads and template specializations?</div> <div>�</div> </div><div><font face="Arial">Hmmm - a small code example might make this easier to understand</font></div> <div><font face="Arial"></font>�</div></div></div></blockquote><div>[...]</div><div>I am a little bit in hurry today, but will submit the example tomorrow.</div><div><br></div><div><br></div><div>With Kind Regards,</div> <div>Ovanes</div><div>�</div></div>