strong_type
strong_type copied to clipboard
Import std module
These changes optionally all the library to be built and consumed using import std;
rather than classic old style #include <meow>
. This currently works for Visual Studio and Clang using libc++. It required the latest CMake 3.30 and Clang versions.
This is not an attempt to create a module from the library, which would be nice to have, only to use the std module.
In CMake everything is guarded by a STRONG_TYPE_IMPORT_STD_LIBRARY
variable. In code stuff is guarded by a macro of the same name. By default STRONG_TYPE_IMPORT_STD_LIBRARY is OFF is CMake so by default everything works exactly as now.
Many of the code changes are of the form
#if defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
import std;
#else
#include <type_traits>
#include <initializer_list>
#include <utility>
#endif
Note both MSVC and clang can do an old style #include
before an import std;
but both give error when you do the reverse. For this reason in the tests the #include <catch2.hpp>
had to be moved to be the first include as it does unguarded #include <meow>
.
So as as user I can now #include strong_type.hpp
with STRONG_TYPE_IMPORT_STD_LIBRARY defined and use import std;
One advantage of doing this is that the std module doesn't leak macros and global namespace things like uint32_t
so you now know that you don't rely on things like that. I did fix a couple of cases where the library used ptrdiff_t
from the global namespace.
Note MSVC does have a bug where it does leak stuff into the GMF, see https://github.com/microsoft/STL/issues/1694 for details.
Anyway hope this is of interest, let me know if you want changes or documentation.