modulename
captaindet
2krnk at gmx.net
Wed Sep 5 18:14:39 PDT 2012
On 2012-09-05 13:05, Jose Armando Garcia wrote:
> On Sep 5, 2012, at 10:56, captaindet <2krnk at gmx.net> wrote:
>
>> On 2012-09-04 15:36, Andrej Mitrovic wrote:
>>> 9/4/12, Ellery Newcomer<ellery-newcomer at utulsa.edu> wrote:
>>>> On 09/04/2012 12:41 PM, Andrej Mitrovic wrote:
>>>>> __FILE__?
>>>>>
>>>>
>>>> It doesn't necessarily have the exact package hierarchy.
>>>
>>> We could really use __MODULE__ then. I think it's been asked
>>> before but I didn't see any enhancement request in buzilla.
>>
>> +1 would love this too
>>
>> so far tried to get away with __FILE__ but this has issues, as
>> noted before.
>>
>>
>> on a slightly different note, __FILE__ and __LINE__ are not quite
>> doing what they are supposed to do either:
>>
>> http://dlang.org/template.html Template Value Parameters "The
>> __FILE__ and __LINE__ expand to the source file name and line
>> number at the point of instantiation."
>>
>> unfortunately, they only do this for functions (sort of¹), not for
>> other templates.
>
> It should work for templates too; std.log uses this extensively. Or
> at least it used to work. Can you post the code sample where it
> doesn't work?
i had a quick look at std.log and it seems to use __LINE__ and __FILE__ only as function argument defaults or parameter defaults for templated functions. these are the only cases where it actually works (with the one syntax catch though). however, it does not work for bare/mixin tamplates, templated structs or templated classes. (so i ended up writing factory functions for my code)
here a test program:
/**
__LINE__ testing for
F := function S := struct C := class T := template
MT := mixin template
as
A := function value argument P := template value parameter
using dmd2.060 /windows prints:
Instantiating Code starts line: 63
F(A)
OK : captured line = 67
T(P)
FAIL : captured line = 43
MT(P)
FAIL : captured line = 46
TF()(A)
OK : captured line = 78
TF(P)(): short call syntax: TF_P()
OK : captured line = 82
TF(P)(): longer call syntax: TF_P!()()
FAIL : captured line = 52
TS(P)
FAIL : captured line = 55
TC(P)
FAIL : captured line = 58
**/
module testline;
import std.stdio;
size_t F_A( size_t l = __LINE__ ){
return l; }
template T_P( size_t l = __LINE__ ){
enum size_t t_p = l; }
mixin template MT_P( size_t l = __LINE__ ){
enum size_t mt_p = l; }
size_t TF_A()( size_t l = __LINE__ ){
return l; }
size_t TF_P( size_t l = __LINE__ )(){
enum size_t _l = l; return _l; }
struct TS_P( size_t l = __LINE__ ){
size_t _l = l; }
class TC_P( size_t l = __LINE__ ){
size_t _l = l; }
void main(){
size_t L = __LINE__; // if things work: __LINE__ > L
writeln("\nInstantiating Code starts line: ", L);
writeln("\nF(A)");
auto l_f_a = F_A();
writeln((l_f_a>L)?"OK":"FAIL", " : captured line = ", l_f_a);
writeln("\nT(P)");
writeln((T_P!().t_p>L)?"OK":"FAIL", " : captured line = ", T_P!().t_p);
writeln("\nMT(P)");
mixin MT_P!();
writeln((mt_p>L)?"OK":"FAIL", " : captured line = ", mt_p);
writeln("\nTF()(A)");
auto l_tf_a = TF_A!()();
writeln((l_tf_a>L)?"OK":"FAIL", " : captured line = ", l_tf_a);
writeln("\nTF(P)(): short call syntax: TF_P()");
auto l_tf_p = TF_P();
writeln((l_tf_p>L)?"OK":"FAIL", " : captured line = ", l_tf_p);
writeln("\nTF(P)(): longer call syntax: TF_P!()()");
auto l_tf_p2 = TF_P!()();
writeln((l_tf_p2>L)?"OK":"FAIL", " : captured line = ", l_tf_p2);
writeln("\nTS(P)");
TS_P!() ts_p;
writeln((ts_p._l>L)?"OK":"FAIL", " : captured line = ", ts_p._l);
writeln("\nTC(P)");
auto tc_p = new TC_P!();
writeln((tc_p._l>L)?"OK":"FAIL", " : captured line = ", tc_p._l);
}
More information about the Digitalmars-d-learn
mailing list