Announcement

Collapse
No announcement yet.

Coroutines & Modules Added For C++20

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #41
    Originally posted by atomsymbol View Post
    Exactly.
    so, since compiler doesn't need fileds, you are free to not give him fields. give him methods and put fields somewhere else (like in derived class for virtual case)

    Comment


    • #42
      Originally posted by atomsymbol View Post
      [I]C++ forces the programmer to define types of fields of a struct/class before the struct/class is defined. This is putting a very strict constraint on the ordering of struct data types in the source code. You cannot call a virtual method (defined elsewhere !!!) before the struct definition has seen the definition of the types of its fields, while obviously the knowledge of fields is immaterial to the virtual method call.
      You are free to define a base class devoid of data members that just contains virtual member function definitions, and call them just fine, even without knowledge of the fields that some derived class (that you actually have a reference to and call the member function of) added to the base class. So I don't see your problem.

      Comment


      • #43
        Regarding modules: Apart from those who just want modules to improve build speeds, there are also those who dream of shipping binary "modules" rather than libraries + source header files because they dislike open source as a business model, and hope that "modules" will be easier to ship without lots of source code in lengthy header files. Only time will tell how often this feature will be used an abused. And whether compiler makers will succeed to let modules actually work faster and more flexible than "pre-compiled headers".

        Comment


        • #44
          Originally posted by atomsymbol View Post
          I still think the requirement of knowing sizeof(T) and alignof(T)
          I still think you don't understand what a "use case" is.

          Originally posted by atomsymbol View Post
          Invoking T's default constructor, destructor, assignment operator, or copy-constructor: These are plain function calls, unless inlining. Default constructor/etc are automatically marked as inline by current compilers - a current-compiler-specific feature.
          To invoke a default constructor/destructor/copy-constructor/assignment operator requires the compiler to instantiate them, for which it needs the full details of the members.

          Comment


          • #45
            Originally posted by cj.wijtmans View Post

            so you cant import a module? the compiler should be able to use the same information that a header contains (except for macros and certain templates but those shouldnt exist in C++ anyway)
            Yes, it's almost that.
            Modules are imported almost like headers are, but unlike headers they don't ship macros.

            Comment


            • #46
              Originally posted by coder View Post
              I still think you don't understand what a "use case" is.


              To invoke a default constructor/destructor/copy-constructor/assignment operator requires the compiler to instantiate them, for which it needs the full details of the members.
              Yes, more specifically, it needs to allocate space first before running the constructor on that space. Which is why factory methods can work-around the issue by calling the constructor from a place where its full definition is known. Or you use the d-pointer/pimpl design and just have the member be a single pointer, and then let the constructor allocate as much space as it needs in the private pointer, but that comes at the cost of an extra indirection, but has the advantage of being possible to expand and change without breaking the ABI, thus can be used for upgradable libraries.

              Comment

              Working...
              X