<html><head></head><body class="" style="background-color: rgb(255, 255, 255); line-height: initial;"> <div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">> <span style="font-family: Calibri, 'Slate Pro', sans-serif; line-height: initial;"></span><span style="font-family: sans-serif; line-height: initial;">You mean the two instantiations of the same specialization would access different friends? That’s ill-formed, NDR.</span></div> <div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><br></div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">No, two different specializations of the same template (of course).</div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><br></div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">> <span style="font-family: sans-serif; line-height: initial;">Your utility is only intended for use within functions, so those are what’s relevant.</span></div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><span style="font-family: sans-serif; line-height: initial;"><br></span></div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><span style="font-family: sans-serif; line-height: initial;">I think you are focusing on the wrong part; the instantiation order of the functions has nothing to do with the template default-arguments (which effectively instantiates the class template).. the template default-arguments are what is important.</span></div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><span style="font-family: sans-serif; line-height: initial;"><br></span></div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><span style="font-family: sans-serif; line-height: initial;">In reply to the rest: the code is confirming, no edit is pending, there are cases where the order of function template instantiation matters - but the example provided is not one of them.<br><span style="line-height: initial; font-size: initial; text-align: initial;"><br></span></span></div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><span style="font-family: sans-serif; line-height: initial;"><span style="line-height: initial; font-size: initial; text-align: initial;">It is important to note that constexpr functions follow the same rules of normal functions, and just to make this even more clear one could also have expressed the method in the post by "abusing" default-arguments (non-template, regular arguments) since these expressions are said to be evaluated each time the function is invoked.<br><br>The use of a template instead of a non-template is simply because the upcoming examples will be working with a similar concept (since that is shorter, but regular function default-arguments can accomplish the same thing).</span></span></div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><span style="font-family: sans-serif; line-height: initial;"><br></span><span style="font-family: sans-serif; line-height: initial; font-size: initial; text-align: initial;"></span></div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><span style="font-family: sans-serif; line-height: initial;"><br></span></div> <div style="font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">:: Filip Roséen (via BlackBerry)<br>:: +46701448424 <br>:: ***@gmail.com<br><br></div> <table width="100%" style="background-color:white;border-spacing:0px;"> <tbody><tr><td colspan="2" style="font-size: initial; text-align: initial; background-color: rgb(255, 255, 255);"> <div style="border-style: solid none none; border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt 0in 0in; font-family: Tahoma, 'BB Alpha Sans', 'Slate Pro'; font-size: 10pt;"> <div><b>From: </b>David Krauss</div><div><b>Sent: </b>Monday, April 27, 2015 8:35 AM</div><div><b>To: </b>std-***@isocpp.org</div><div><b>Reply To: </b>std-***@isocpp.org</div><div><b>Subject: </b>Re: [std-discussion] non-constant constant-expressions, is it really possible?</div></div></td></tr></tbody></table><div style="border-style: solid none none; border-top-color: rgb(186, 188, 209); border-top-width: 1pt; font-size: initial; text-align: initial; background-color: rgb(255, 255, 255);"></div><br><div id="_originalContent" style=""><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On 2015–04–27, at 1:53 PM, Filip Roséen <<a href="mailto:***@gmail.com" class="">***@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">> 1. Your utility won’t work from inside a template. It must always be
used from a non-template context, because a second instantiation of the
same template would see the friends generated by the first
instantiation. Every specialization that is used at all has at least two
points of instantiation, including one at the end of the TU. (In
practice, though, you will probably get consistent behavior for
templates with only exactly two PoI’s.)<br class=""><br class=""></div>Unless they rely on different friends, so the above is not really an issue, </div></div></div></div></div></blockquote><div><br class=""></div><div>You mean the two instantiations of the same specialization would access different friends? That’s ill-formed, NDR.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="">also; class template specializations has at most one point of instantiation - not two, that only applies to function templates.<br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>Your utility is only intended for use within functions, so those are what’s relevant.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="">> The problem is that the standard doesn’t describe an order for the instantiations to happen.<br class=""><br class=""></div>Unless we are talking dependency, where it must happen in some order - this does not only include literally dependent types. The example in the current post is not sufficient enough to explain this in detail, but an explanation will be included in upcoming posts (there are more neat little tricks to be published).<br class=""></div></div></div></div></blockquote><div><br class=""></div><div>There is no dependency between the statements in your post, and that seems to be the whole purpose: to let compile-time information flow from one statement to the next without using the type system.</div><div><br class=""></div><div>It would be more responsible to provide a disclaimer in your article if you believe its examples to be nonconforming, especially if an edit is in the works.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class="">> Your utility requires the point instantiation of the friend function to
be before the point of use. Otherwise, it wouldn’t be in scope. However,
there is no point of instantiation defined for friends at all. You’re
relying on friends being treated like classes, not like other functions,
which seems especially brittle.<br class=""><br class=""></div>This is not entirely true, it requires the point of instantiation of the class-template specialization to be where it needs to be; </div></div></div></blockquote><div><br class=""></div><div>Calling the constexpr function requires its definition to precede the use. You’re assuming that the functions are defined by the class template instantiation: “Please note that the functions <code class="">func (short)</code> and <code class="">func (float)</code>
are <em class="">undefined</em> until <code class="">A<short></code> and <code class="">A<float></code> have been instantiated,
respectively.” This is not a safe assumption, because the point of instantiation may render the definition invisible to the current function.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">please note that default template-arguments are <b class="">not</b> part of the specialization itself, that means that `sizeof(...)` used as a default-argument to the template function effectively puts the instantiation of the relevant class prior to `main` (not prior to the instantiation of the function template specialization). The post "abuses" the instantiation of class template specializations, not function template specializations.<br class=""></div></div></div></blockquote><div><br class=""></div><div>I’m not sure what you mean by “prior to the instantiation of the function template specialization.” Points of instantiation are before or after non-template declarations at namespace scope. Classes come before, functions come after. Friends are unspecified, but they are functions, so we can extrapolate.</div><div><br class=""></div><div>Actually, constexpr function templates can’t usually form constant expressions at all according to the current rules. This needs a DR.</div></div>
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:std-discussion+***@isocpp.org">std-discussion+***@isocpp.org</a>.<br>
To post to this group, send email to <a href="mailto:std-***@isocpp.org">std-***@isocpp.org</a>.<br>
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-discussion/">http://groups.google.com/a/isocpp.org/group/std-discussion/</a>.<br>
<br><!--end of _originalContent --></div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:std-discussion+***@isocpp.org">std-discussion+***@isocpp.org</a>.<br />
To post to this group, send email to <a href="mailto:std-***@isocpp.org">std-***@isocpp.org</a>.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-discussion/">http://groups.google.com/a/isocpp.org/group/std-discussion/</a>.<br />