On Mon, 22 Dec 2014 10:41:10 GMT, Mathias LANG wrote:

Okay. I can't see why you would use it (looks like lack of SoC), could you provide an use case ?

I just don't want to serialize data with default values. This is useless overhead (extra network traffic and CPU load).

Okay. I can't see why you would use it (looks like lack of SoC), could you provide an use case ?
Anyway, I can imagine something like this fitting into Vibe.d:

struct MyStruct {
  @optional(canSerialize) int value;
  bool canSerialize(int value) { return value != 42; }
}

Here, 'MyStruct.value' will only be serialized if the return value from canSerialize (which can be either a member or a free function) is true. Would that do ?

Good idea. Like attributes for web interfaces:

struct MyStruct {
    bool canSerialize() { return this.value != 42; }
    @optional!canSerialize int value = 42;
}