proposal: allow 'with(Foo):' in addition to 'with(Foo){..}'
Era Scarecrow via Digitalmars-d
digitalmars-d at puremagic.com
Sun Aug 10 14:01:36 PDT 2014
On Sunday, 10 August 2014 at 20:12:56 UTC, Walter Bright wrote:
> On 8/10/2014 11:34 AM, Era Scarecrow wrote:
>> 5. Access permissions (public/private/protected).
>> 6. File length attributes (@safe: @system: @trusted:)
>
> Again, that is for declarations, not statements.
Does with have to be only for statements?
Real example. In my code somewhere i have a large list of enum
types that specify a type of formatting and visibility options.
enum FlagStates {
def = 0x0, //Default Value.
changed = 1, ///Has changed (From original state)
readOnly = 1 << 1, ///This field/subrecord/record is readonly
isOriginal = 1 << 2, ///when loaded except when marked
deleted/invisible
invisible = 1 << 3, ///
deleted = 1 << 4, ///
//29 out of 32 flags are defined
}
next i'll have a struct that holds this as part of it's
declaration...
///Details for specific parts/fields
struct NotePart {
ValueType type; ///type of value (string, etc. See flags.d)
string id; ///specific output/identifier to print (If any)
int _size;
Flags flags; ///default flags used. Relies on FlagStates
//etc...
}
alias immutable(char)[4] NString;
struct SubRecordParts {
NString name; ///specific subrecord
NString requ; ///must be within record (or base subrecord)
int size; ///how big (Helps identify, TES3 header is 300 for
example.
NotePart[] notes; ///Specify all the individual fields
//etc
}
Now since i can't use with(): I'm forced to do aliases, and a
lot of them...
private alias NotePart NP;
private alias ValueType VT;
private alias FlagStates.noPrint noPrint;
private alias FlagStates.noChange noChange;
private alias FlagStates.hashPrint hashPrint;
private alias FlagStates.noPrintClashes noPrintClashes;
private alias FlagStates.noPrintNull noPrintNull;
//there's at least like 200 entries in here.
immutable SubRecordParts subParts[] = [
{"DATA", "INFO", 12, [
{VT.raw, "Unknown", 4, Flags(noPrint, noChange)},
{VT.i_32, "Disposition"},
{VT.i_8, "Rank"},
{VT.ranged_8, "Gender"},
{VT.i_8, "PCRank"},
{VT.raw, "Unknown", 1, Flags(noPrint, noChange)}]},
{"VHGT", "LAND", 4232, [
{VT.float_32, "Base Height"},
{VT.raw, "Height Data", 4228, Flags(noChange, noPrintClashes,
hashPrint)}]},
//etc etc. This is a more verbose section than most of the
rest. Most include the noPrintNull flag
];
Had i been able to use with() i could have avoided the aliases
above and probably just done a single line before using it
heavily.
with(FlagStates, ValueType):
There wouldn't have been clashing because they each hold
different types of data, and it's all immutable static values
anyways.
More information about the Digitalmars-d
mailing list