shared and getParameterStorageClasses bug?

Petar Petar
Sun Aug 23 21:14:38 UTC 2020

On Sunday, 23 August 2020 at 13:44:30 UTC, Jean-Louis Leroy wrote:
> On Sunday, 23 August 2020 at 06:42:02 UTC, Petar Kirov 
> [ZombineDev] wrote:
>> From a grammar point of view, type qualifiers (`const`, 
>> `immutable`, `inout` and `shared`) can appear as 4 different 
>> entities:
>> 1. Type constructors [0]
>> 2. Variable storage classes [1]
>> 3. Parameter attributes [2]
>> 4. Member function attributes [3]
>> Parameter attributes grammatically include both UDAs and 
>> parameter storage classes (confusingly named `InOut` in the 
>> spec), so we can actually collapse the grammatical entities
>> related to variables (which include parameters) to just 2 
>> kinds: type constructors and storage classes.
>> Semantically:
>>    Q T x;  // A) storage class syntax
>>    Q(T) x; // B) type constructor syntax
>> A) and B) are equivalent (where `Q` is some type qualifier and 
>> `T` is some type).
> Thanks. Then my follow-up question is: how do I retrieve the 
> parameter type constructors? Without resorting on scanning the 
> stringified parameter like here:
> enum isSharedParameter(alias fun, uint param) =
>   Parameters!fun[param..param+1].stringof.indexOf("shared") != 
> -1;
> (of course this is not robust: it would give false positives 
> with types that contain the substring "shared").
> My actual goal is to extract them in the same fashion as the 
> storage classes, e.g.:
> void foo(lazy const shared Object);
> static assert(parameterTypeConstructors!foo == tuple("const", 
> "shared"));
> Do I really have to parse a string like "(lazy 
> shared(const(Object)))"? And, how reliable would this solution 
> be?

Hmm, why do you need to extract them in the same fashion? For use 
in string mixins? If you just want to create a proxy function 
then simply using std.traits.Parameters should do the trick.

If you're writing a meta programming library, then perhaps you 
can consider representing function types as:
1. AliasSeq of the types
2. AliasSeq of the types
3. AliasSeq of the default values
4. AliasSeq of ints, each representing a bitset of the parameter 
storage classes that we're set. Or alternatively string[][].

Another way would be to create a Parameter struct template that 
contains the relevant information and then have an AliasSeq of 
Parameter types for each function type.

More information about the Digitalmars-d mailing list