<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jan 21, 2014, at 5:59 AM, Rahul Jain <<a href="mailto:rahul1.jain@samsung.com">rahul1.jain@samsung.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 9pt; font-family: Arial, arial; margin: 10px; line-height: 1.4; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin-bottom: 5px; font-size: 9pt; font-family: Arial, arial; margin-top: 5px;"> <br class="webkit-block-placeholder"></div><p style="margin-bottom: 5px; font-size: 9pt; font-family: Arial, arial; margin-top: 5px;">Hi all,</p><div style="margin-bottom: 5px; font-size: 9pt; font-family: Arial, arial; margin-top: 5px;"> <br class="webkit-block-placeholder"></div><div>Note - this is with respect to C++ 03.</div><div></div><div><em></em> </div><div><em>Test code:</em></div><div><em></em> </div><div><em>template <int> struct A {};<br>int const i = {42};<br>typedef A<i> Ai;</em></div></div></blockquote><div><br></div>Short, snarky answer - you can’t bracket-initialize a variable in c++03</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>int const i = {42};</div><div><br></div><div><blockquote type="cite"><div style="font-size: 9pt; font-family: Arial, arial; margin: 10px; line-height: 1.4; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div>For non-type template argument, standard (C++ 03) says that:</div><div></div><div><em>14.3.2 / 1</em></div><p style="margin-bottom: 5px; font-size: 9pt; font-family: Arial, arial; margin-top: 5px;"><em>A template-argument for a non-type, non-template template-parameter shall be one of:</em></p><ul><em></em><li style="margin-bottom: 5px; font-size: 9pt; font-family: Arial, arial; margin-top: 5px;"><em>an<span class="Apple-converted-space"> </span><strong>integral constant-expression</strong><span class="Apple-converted-space"> </span>of integral or enumeration type; or ......</em></li></ul><div>For the test code above, the statement '<em>typedef A<i> Ai</em>', should the compiler</div><div>check the rhs (rvalue) of variable 'i' to determine if it is a constant or not?</div><div>Shouldnt it just check the type of i (which is declared as const)?</div><div>Whether 'i' evaluates to constant (at compile time) or not should be the responsibility of compiler</div><div>while processing statement '<em>int const i = {42}</em>' and not '<em>typedef A<i> Ai' ? Isnt it?</em></div><div> </div><div>Another analogy:<br>For arrays, the size of the array needs to be a compile time constant. So, the following code :</div><div></div><div><em></em> </div><div><em>int const x = 42;</em></div><div><em>int z[x];</em></div><div></div><div> </div><div>For the statement<span class="Apple-converted-space"> </span><em>'int z[x]'</em>, will the compiler evaluate the rhs of<span class="Apple-converted-space"> </span><em>'x'</em><span class="Apple-converted-space"> </span>to check if it evaluates to constant at runtime</div><div>or will it just see that '<em>x</em>' is of 'integer const' type and hence there is no problem with the array declaration?</div><div>Whether '<em>x</em>' evaluates to constant should be the responsibility of compiler while processing statement '<em>int const x=42</em>'</div><div>and not while processing '<em>int z[x]</em>' ?</div><div></div><div> </div><div>Should this analogy be applicable to non-type template argument?</div><div></div><p style="margin-bottom: 5px; font-size: 9pt; font-family: Arial, arial; margin-top: 5px;">Please throw some light on this, am I missing any particular case?</p></div></blockquote><br></div><div>My understanding (which may be flawed) is that the compiler needs to see both:</div><div>* That the compiler needs to be able to determine that the value it needs is const</div><div>* That the compiler can see what the value actually is, so that it can allocate space for the array, or instantiate the template.</div><div><br></div><div><br></div><div>So, this would not work:</div><div><br></div><span class="Apple-tab-span" style="white-space:pre">     </span>extern const int i;<div><span class="Apple-tab-span" style="white-space:pre">      </span>template <int> struct A {};<br><span class="Apple-tab-span" style="white-space:pre"> </span>typedef A<i> Ai;</div><div><br></div></body></html>