search of a workaround

monarch_dodra monarchdodra at gmail.com
Sun Feb 10 00:38:21 PST 2013


On Saturday, 9 February 2013 at 22:14:45 UTC, Namespace wrote:
> Why isn't there 'const' in ParameterStorageClass?
> How could I detect that my Parameter storage class is 'in'?

It's an ambiguity in the term "StorageClass" in D, which is 
different from "TypeQualifier". Const is part of the type. 
"StorageClass" means modifiers when you pass to a function.

As for "in" (or inout):

Apparently, they aren't "true" StorageClass, because the compiler 
re-writes them to "const ref" or "scope" something anyways, 
that's why they don't appear in the list.

On Saturday, 9 February 2013 at 22:54:23 UTC, Namespace wrote:
> On Saturday, 9 February 2013 at 22:23:07 UTC, Namespace wrote:
>> It seems your template has problems with this:
>>
>> struct A { }
>>
>> class B {
>> public:
>> 	const int bar(ref A a) {
>> 		return 42;
>> 	}
>> 	
>> 	mixin(rvalue!(bar));
>> }
>>
>> remove the 'const' and it works fine.
>
> It seems that D has no functionality, to detect if a method is 
> const.

Well, I did mention "Also, I didn't code the FunctionAttribute 
part, but that's just because it's late and I want to sleep". I 
even left a big "todo" in there :)

On Sunday, 10 February 2013 at 00:01:32 UTC, Namespace wrote:
> This works so far:
>
> auto funcAttr = functionAttributes!(fun);
> if (FunctionAttribute.pure_ & funcAttr) s ~= " pure";
> if (FunctionAttribute.nothrow_ & funcAttr) s ~= " nothrow";
> if (FunctionAttribute.ref_ & funcAttr) s ~= " ref";
> if (!isMutable!(typeof(fun))) s ~= " const";
>
> But it's curious that FunctionAttributes has no const, 
> immutable, inout or shared...

I I have no idea. File a bug maybe?

Either it'll be valid, or you'll get the "it would be redundant" 
reply, in which case the docs would *need* to be upgraded.


More information about the Digitalmars-d-learn mailing list