<br><br><div class="gmail_quote">On Thu, Sep 9, 2010 at 12:47 PM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com">rjmccall@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"><div><div><div></div><div class="h5"><div>On Sep 9, 2010, at 4:23 AM, Dominic Laflamme wrote:</div><blockquote type="cite"><span style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:medium"><div style="font-size:10pt;font-family:Tahoma">
I am porting a bunch of GLSL code over to LLVM and am wondering how I can setup constructors for a certain type.<span> </span><br><br>example:<br><font face="Courier New"><br></font><font face="Courier New"><snip></font><font face="Courier New"><br>
</font><blockquote><font face="Courier New">typedef float float4 __attribute__((ext_vector_type(4)));</font><br><br><font face="Courier New">float4 float4(float r, float g, float b, float a )</font><br><font face="Courier New">{</font><br>
<blockquote><font face="Courier New">float4 ret = {r,g,b,a};</font><br><font face="Courier New">return ret;</font><br></blockquote><font face="Courier New">}</font><br><br><font face="Courier New">float4 float4(float r, float g, float b )</font><br>
<font face="Courier New">{</font><br><blockquote><font face="Courier New">float4 ret = {r,g,b,1.0};</font><br><font face="Courier New">return ret;</font><br></blockquote><font face="Courier New">}</font><br></blockquote><font face="Courier New"></snip></font><br>
<br>Of course this wont work since the function are using the same name, but any idea how I can setup these types of constructors? Should I declare float4 as a struct and overload the constructors? Can the ext_vector_type extension provide some help?<br>
</div></span></blockquote><div><br></div></div></div>In C++, you could certainly just make float4 a class that wraps a vector and has an implicit conversion to vector type.  Alternatively, if you're willing to use different function names, you can just make these overloaded functions.  Otherwise I don't think there's a reasonable solution short of inventing a crazy new language feature.</div>
</div></blockquote><div><br></div><div>In C++0x, it would be better to use the staticly-sized std::array<intval> type rather than a dynamically sized vector.  Or maybe even a std::tuple.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word"><div><br></div><div>It's not unreasonable for us to support direct-initialization of vector types a la 'float4(a,b,c,d)' as a generic form of vector initialization in C++, but obviously that wouldn't extend to the three-argument version.</div>
<div><br></div></div></blockquote><div><br></div><div>Also in C++0x, you could use std::initializer_list construction to achieve this.  Calling syntax would be:</div><div><br></div><div>float4 f1 = {2.0, 2.0, 2.0, 2.0);</div>
<div>float4 f2 = {2.0, 2.0, 2.0};  // std::initializer_list ctor would recognize only three elements and do the 'right' thing for the alpha.</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 style="word-wrap:break-word"><div></div><font color="#888888"><div>John.</div></font></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br><div>Too bad we don't have that support yet.. :(</div><div><br></div>