<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 24, 2019 at 4:11 PM J. Gareth Moreton <<a href="mailto:gareth@moreton-family.com">gareth@moreton-family.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>"constexpr" is essentially to C++ as "pure" would be to FPC.
Some of the methods that involve pointers and var parameters
(which is probably the closest equivalent to the "&"
parameters in C++) may be flagged as impure because they can't be
dereferenced at compile time. Nevertheless, a function that
simply returns a formatted string, rather than writing directly to
an output stream, is certainly doable.</p></div></blockquote><div><br></div><div>Well, just to be sure we're on the same page in general, the hypothetical Pascal equivalent of that program would look something like this I guess:</div><div><br></div><div><pre style="color:rgb(0,0,0)"><code><font size="2" face="Courier New"><font color="black"><b>program </b>Example<font color="red">;
<b>{$mode ObjFPC}
{$modeswitch AdvancedRecords}
</b></font><b>uses </b>SysUtils<font color="red">;
</font><b>type
generic </b>TVec3<font color="red"><</font>T<font color="red">> = </font><b>record
</b>X<font color="red">, </font>Y<font color="red">, </font>Z<font color="red">: </font>T<font color="red">;
</font><b>class function </b>Create<font color="red">(</font><b>const </b>IX<font color="red">, </font>IY<font color="red">, </font>IZ<font color="red">: </font>T<font color="red">): </font>TVec3<font color="red">; </font>static<font color="red">; </font>pure<font color="red">;
</font><b>class operator </b><font color="red">+(</font>constref LHS<font color="red">, </font>RHS<font color="red">: </font>TVec3<font color="red">): </font>TVec3<font color="red">; </font><b>vectorcall</b><font color="red">; </font>pure<font color="red">;
</font><b>class operator </b><font color="red">-(</font>constref LHS<font color="red">, </font>RHS<font color="red">: </font>TVec3<font color="red">): </font>TVec3<font color="red">; </font><b>vectorcall</b><font color="red">; </font>pure<font color="red">;
</font><b>class operator </b><font color="red">*(</font>constref LHS<font color="red">, </font>RHS<font color="red">: </font>TVec3<font color="red">): </font>TVec3<font color="red">; </font><b>vectorcall</b><font color="red">; </font>pure<font color="red">;
</font><b>class operator </b><font color="red">/(</font>constref LHS<font color="red">, </font>RHS<font color="red">: </font>TVec3<font color="red">): </font>TVec3<font color="red">; </font><b>vectorcall</b><font color="red">; </font>pure<font color="red">;
</font><font color="blue"><b>// This one doesn't really need to be "pure"... normal inlining would be fine.
</b></font><b>procedure </b>Print<font color="red">; </font>pure<font color="red">;
</font><b>end</b><font color="red">;
</font><b>class function </b>TVec3<font color="red">.</font>Create<font color="red">(</font><b>const </b>IX<font color="red">, </font>IY<font color="red">, </font>IZ<font color="red">: </font>T<font color="red">): </font>TVec3<font color="red">;
</font><b>begin
with </b>Result <b>do begin
</b>X <font color="red">:= </font>IX<font color="red">;
</font>Y <font color="red">:= </font>IY<font color="red">;
</font>Z <font color="red">:= </font>IZ<font color="red">;
</font><b>end</b><font color="red">;
</font><b>end</b><font color="red">;
</font><b>class operator </b>TVec3<font color="red">.+(</font>constref LHS<font color="red">, </font>RHS<font color="red">: </font>TVec3<font color="red">): </font>TVec3<font color="red">; </font><b>vectorcall</b><font color="red">;
</font><b>begin
</b>Result <font color="red">:= </font>TVec3<font color="red">.</font>Create<font color="red">(</font>LHS<font color="red">.</font>X <font color="red">+ </font>RHS<font color="red">.</font>X<font color="red">, </font>LHS<font color="red">.</font>Y <font color="red">+ </font>RHS<font color="red">.</font>Y<font color="red">, </font>LHS<font color="red">.</font>Z <font color="red">+ </font>RHS<font color="red">.</font>Z<font color="red">);
</font><b>end</b><font color="red">;
</font><b>class operator </b>TVec3<font color="red">.-(</font>constref LHS<font color="red">, </font>RHS<font color="red">: </font>TVec3<font color="red">): </font>TVec3<font color="red">; </font><b>vectorcall</b><font color="red">;
</font><b>begin
</b>Result <font color="red">:= </font>TVec3<font color="red">.</font>Create<font color="red">(</font>LHS<font color="red">.</font>X <font color="red">- </font>RHS<font color="red">.</font>X<font color="red">, </font>LHS<font color="red">.</font>Y <font color="red">- </font>RHS<font color="red">.</font>Y<font color="red">, </font>LHS<font color="red">.</font>Z <font color="red">- </font>RHS<font color="red">.</font>Z<font color="red">);
</font><b>end</b><font color="red">;
</font><b>class operator </b>TVec3<font color="red">.*(</font>constref LHS<font color="red">, </font>RHS<font color="red">: </font>TVec3<font color="red">): </font>TVec3<font color="red">; </font><b>vectorcall</b><font color="red">;
</font><b>begin
</b>Result <font color="red">:= </font>TVec3<font color="red">.</font>Create<font color="red">(</font>LHS<font color="red">.</font>X <font color="red">* </font>RHS<font color="red">.</font>X<font color="red">, </font>LHS<font color="red">.</font>Y <font color="red">* </font>RHS<font color="red">.</font>Y<font color="red">, </font>LHS<font color="red">.</font>Z <font color="red">* </font>RHS<font color="red">.</font>Z<font color="red">);
</font><b>end</b><font color="red">;
</font><b>class operator </b>TVec3<font color="red">./(</font>constref LHS<font color="red">, </font>RHS<font color="red">: </font>TVec3<font color="red">): </font>TVec3<font color="red">; </font><b>vectorcall</b><font color="red">;
</font><b>begin
</b>Result <font color="red">:= </font>TVec3<font color="red">.</font>Create<font color="red">(</font>LHS<font color="red">.</font>X <font color="red">/ </font>RHS<font color="red">.</font>X<font color="red">, </font>LHS<font color="red">.</font>Y <font color="red">/ </font>RHS<font color="red">.</font>Y<font color="red">, </font>LHS<font color="red">.</font>Z <font color="red">/ </font>RHS<font color="red">.</font>Z<font color="red">);
</font><b>end</b><font color="red">;
</font><b>procedure </b>TVec3<font color="red">.</font>Print<font color="red">;
</font><b>begin
case </b>GetTypeKind<font color="red">(</font>T<font color="red">) </font><b>of
</b>tkFloat<font color="red">:
</font>WriteLn<font color="red">(</font>Format<font color="red">(</font><font color="blue">'[%.4f, %.4f, %.4f]'</font><font color="red">, [</font>X<font color="red">, </font>Y<font color="red">, </font>Z<font color="red">]));
</font>tkInteger<font color="red">, </font>tkInt64<font color="red">, </font>tkQWord<font color="red">:
</font>WriteLn<font color="red">(</font>Format<font color="red">(</font><font color="blue">'[%d, %d, %d]'</font><font color="red">, [</font>X<font color="red">, </font>Y<font color="red">, </font>Z<font color="red">]));
</font><b>otherwise
</b>WriteLn<font color="red">(</font><font color="blue">'[N/A, N/A, N/A]'</font><font color="red">);
</font><b>end</b><font color="red">;
</font><b>end</b><font color="red">;
</font><b>type </b>TVec3F <font color="red">= </font><b>specialize </b>TVec3<font color="red"><</font>Single<font color="red">>;
</font><b>const
</b>A<font color="red">: </font>TVec3F <font color="red">= (</font>X<font color="red">: </font><font color="navy">1.2</font><font color="red">; </font>Y<font color="red">: </font><font color="navy">2.4</font><font color="red">; </font>Z<font color="red">: </font><font color="navy">3.8</font><font color="red">);
</font>B<font color="red">: </font>TVec3F <font color="red">= (</font>X<font color="red">: </font><font color="navy">2.1</font><font color="red">; </font>Y<font color="red">: </font><font color="navy">4.2</font><font color="red">; </font>Z<font color="red">: </font><font color="navy">8.3</font><font color="red">);
</font><font color="blue"><b>// You can't do the next part currently, obviously
</b></font>C<font color="red">: </font>TVec3F <font color="red">= </font>A <font color="red">+ </font>B<font color="red">;
</font>D<font color="red">: </font>TVec3F <font color="red">= </font>A <font color="red">- </font>B<font color="red">;
</font>E<font color="red">: </font>TVec3F <font color="red">= </font>A <font color="red">* </font>B<font color="red">;
</font>F<font color="red">: </font>TVec3F <font color="red">= </font>A <font color="red">/ </font>B<font color="red">;
</font><b>begin
</b>C<font color="red">.</font>Print<font color="red">();
</font>D<font color="red">.</font>Print<font color="red">();
</font>E<font color="red">.</font>Print<font color="red">();
</font>F<font color="red">.</font>Print<font color="red">();
</font><b>end</b><font color="red">.</font></font></font></code></pre></div></div></div>