Technology

CppCon 2019: C++ Modules: Guides for The Working Software developer

Gabriel Dos Reis

<h1>existing practice and Challenges</h1>
  • build time scalability of idiomatic C++

Fragile and Outdated Linking Mode

Program = collection of independently translated source files

Macros are a big problem

Modules accepted for C++20

What did we accomplish

  • Languate notions and constructs
    • Componentization
    • Isolation
    • Build throughput
    • Semantics-aware developer tools
  • With transition paths
    • Global module fragments
    • Header units

Module Definition (101)

export module BasicPlane.Figures;
export struct X ...

#include <iostream>
import BasicPlane.Figures;



How does it work?

  • The generated module generates .o plus metadata
  • If name is not exported it is not available

Efficient Pimpl

  • module :private;

Spreading Module Definition

  • “export module” gives module definition
  • “module X” is implementation

Spreading Module Interface

  • Primary module interface


export module BasicPlane.Figures;
export import :PointPart;
export import :RectPart;


export module BasicPlane.Figures:PointPart;
export struct Point {...};

export module BasicPlane.Figures:RectPart;
import :PointPart;
export struct Rectangle {...};
export int width(const Rectangle &); ...



Module Aggregation

export module BasicPlane;

export import BasicPlane.Figures;
export import BasicPlane.Transformations;
export import BasicPlane.Canvas;

Transitioning into modular world, and preparing for modules

module;
#include <sys/stat.h>

export module System.File.Ops;
namespace Sys {
    export stat stat_dierctory(const char *);

    export using ::chmod;
}

Heder Unit: An almost module

import <iostream>
import BasicPlane.Figures;

Kicking the Tires with MSVC, GCC, and clang

gcc.gnu.org/wiki/cxx-modules

Questions

  • Does
    import <iostream>

    obsolete pre-compiled headers? Yes

  • PCH vs usual include. 10 times faster

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.