Bug? tupleof and const string = ""

Andre andre at s-e-a-p.de
Thu Feb 13 08:48:18 PST 2014


Am 13.02.2014 17:42, schrieb Tobias Pankrath:
> On Thursday, 13 February 2014 at 16:37:20 UTC, Andre wrote:
>> Hi,
>>
>> could you have a look whether this is a bug with tupleof?
>> In case you have a const string with a default value,
>> the attribute is not in the tupleof list.
>>
>> struct A {
>>     const string a = "abc";
>>     string d;
>> }
>>
>> void main(){
>>     assert(A().tupleof.length == 2); // fails -> length = 1
>> }
>>
>> Kind regards
>> André
>
> I'm not sure. May guess is the compiler figures that you'll never be
> able to change a and pulls it out of the struct. What I don't know is,
> if it should do this without using immutable or enum.
>
> Besides: I don't think that const elements make any sense. What do you
> want to do?

It is strange, const string attributes without a value are working fine.

The use case is for communication with a database procedure. The 
database procedure want the request in JSON format. I created the
structure similiar to the JSON request and serialize it to JSON.
Some of the values should be constant others should be variable.

Kind regards
André




More information about the Digitalmars-d-learn mailing list