strong_type
strong_type copied to clipboard
Create a strong_type module
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.
- The intent would be to allow users to consume either a module as in
import strong_type;or to continue using headers. - Existing header users should not be affected in any way, so no exiting code should fail to compile etc...
- Ideally it should be orthogonal if users choose to use
import std;when they include strong type headers. - 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.
Oh this does raise the question of code format
STRONG_TYPE_MODULE_EXPORT
template <typename T>
struct Foo {
}
or
STRONG_TYPE_MODULE_EXPORT template <typename T>
struct Foo {
}
The former is maybe easier to review, the later is one less line. I'm happy with whatever you want.
BTW I noticed code like
template <typename D>
template <typename T, typename Tag, typename ... M>
class affine_point<D>::modifier<::strong::type<T, Tag, M...>>
{
I have never seen that before is it the same as
template <typename D, typename T, typename Tag, typename ... M>
Also what does the following do?
template<typename M, typename T>
using modifier = typename M::template modifier<T>;
Got sick at the conference. Bleah....
On code formatting, I have over the years come to prefer easily "diffable" formats, so a format that makes a change local to one line is preferable to one that spreads over several. It's a judgement call, though, as you really don't want the extreme of one syntactic element per line. I used to vaguely prefer this, but then I briefly worked for a company whose coding style made it a challenge to understand what even the smallest change actually changed.
The one in the middle. I wish they were the same, but the language disagrees. https://godbolt.org/z/KGE7W9jaK
For the last one, as far as I remember, that is a work around a compiler bug.