Skip to content

Create a strong_type module #47

@davidhunter22

Description

@davidhunter22

This is a place holder for creating a module from the strong_type source.

Some initial thoughts

This should probably be done following the same model as the MSVC standard library. This is on the grounds that if it works for that it will probably work for strong_type.

  1. The intent would be to allow users to consume either a module as in import strong_type; or to continue using headers.
  2. Existing header users should not be affected in any way, so no exiting code should fail to compile etc...
  3. Ideally it should be orthogonal if users choose to use import std; when they include strong type headers.
  4. Ideally vcpkg, and similar, users should be able to consume the module, there should be an example of how to do this

The main change in the source code is to optionally add the export keyword to all entities that should be exported. This is optional because include users still have to work. This can be done via a a macro like STRONG_TYPE_MODULE_EXPORT that evalutes to export or by default empty. The MSVC standard library uses _EXPORT_STD for this.

The module can be built using import std; however the module should use just import std; not export import std;. This allows users to use the strong_type module but still carry on using #include <meow> for the standard library.

I would suggest that an initial PR is created that just adds the STRONG_TYPE_MODULE_EXPORT macro to the large number of places it is needed and does nothing else. This is because this is by far the bulk of the changes and doing them in a separate PR makes it easier to review but is pretty low risk as the default value of STRONG_TYPE_MODULE_EXPORT is empty.
Note an alternative to adding export to every exported entity would be export namespace strong_type { ... } or export namspace { }.
However these tend to make code brittle to future change as people move code around and can accidentally export stuff that isn't meant to be or visa versa.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions