Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-97870

Utility to force designated initializer

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Server Programmability
    • SP Prioritized List

      I'd like to be able to mark a struct somehow, so that the only way to construct it is with the designated initializer syntax.

      Hypothetical example:

      struct FooArgs {
          REQUIRE_DESIGNATED_INIT(Foo)
      
          int apple;
          int banana;
          int cherry;
          int durian;
          // ...
      };
      void runFoo(FooArgs);
      
      int main() {
          runFoo({5});  // error: you're supposed to use named arguments
          runFoo({.banana = 3, .cherry = 4});  // good
      }
      

      mathias@mongodb.com suggested this and wrote a POC, and I would find this useful for an upcoming project.

            Assignee:
            Unassigned Unassigned
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: