On Wednesday, 17 October 2012 at 06:07:34 UTC, ixid wrote:
Theoretically legal...

void func()
//in/out contracts
body with (E) { //with replaces normal block

}

This seems sensible. Multiple with seems like a recipe for confusion and member name clashes.

True... But if you're planning on going multiple levels of with, then it isn't going to matter much.

In a project of mine I'll have a few different enum types, each one with their own sets of flags used in a structure. So you're looking at something like.. As an off the wall example.

  enum OnOff {off, on}
  enum Speed {stop, slow, medium, fast, reallyFast, lightspeed}
  enum MemoryType {allocated, stack}
enum EngineType {internalCombustion, electrical, magical, warp, teleportion}
  enum Size {tiny, small, medium, large, huge}

  struct Vehicle {
    OnOff state;
    Speed speed;
    const MemoryType memAt;
    const EngineType engine;
    const Size size;
  }

So in this kind of case where none of the enums clash, then manually doing them. True there's a clash from size/speed, but that's fairly easy to fix in the case it's used.

  with (OnOff, Speed, MemoryType, EngineType, Size)
//    or
//  with (OnOff) with(Speed) with(MemoryType)
//      with(EngineType) with(Size)
  {
    Vehicle Enterprise = {off, stop, stack, warp, huge};

    //fully explicit, but doesn't buy you much except clutter
Vehicle Enterprise2 = {OnOff.off, Speed.stop, MemoryType.stack,
                            EngineType.warp, Size.huge};

    //wrong order, enums complain but is fairly obvious
    //based on types (and the error message) how to reorder it.
Vehicle ModelT = {stop, allocated, medium, internalCombustion, off};
  }

Reply via email to