Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard library module #140

Closed
davidhunter22 opened this issue Nov 15, 2022 · 2 comments · Fixed by #141
Closed

Standard library module #140

davidhunter22 opened this issue Nov 15, 2022 · 2 comments · Fixed by #141

Comments

@davidhunter22
Copy link
Contributor

The latest Visual Studio compiler 17.5 has standard library modules.

I am wondering if you want to support using the standard library via a module as well as old style includes.
I have a local branch where I can include all the type_safe header files in a test program using "import std;
If you are interested in this I can push a draft PR for you to look at. I tried to make the minimal amount of changes and to make sure that the default behaviour is everything works as is.

The main changes are

  1. Use a macro in all the headers to choose whether to import or include. Obvisouly the default is to include. For example
#include <type_traits>

becomes

#if defined(TYPE_SAFE_IMPORT_STD_MODULE)
import std;
#else
#include <type_traits>
#endif

In theory you should be able to mix import and old style headers but the MS compiler does not support that yet and may not for a while see microsoft/STL#3195 for STLs comment about this. In any case I think it's a good idead to macro out the old stuff.
2) Fix a couple of cases where the headers assumed things like int8_t were in the global namespace. Note that this cou;d be fixed by using std.compat but I think it's good to not really on global namespace pollution
3) There appears to be a compiler bug that is trigger by including the type_safe header using /std:c++latest switch. I have a MS dev community issues filed for it https://developercommunity.visualstudio.com/t/VS-22-174-templated-constructor-paramet/10202157. I put a couple of fixes in the code guarded by macors so the exiting code is the default.
4) The test program is a new project and is off by default in CMake

option(TYPE_SAFE_IMPORT_STD_MODULE "Build using the standard library modules rather than #include" OFF)

if(TYPE_SAFE_IMPORT_STD_MODULE)
    add_subdirectory(test_std_module/)
endif()

I believe this includes all the changes needed to make the type_headers work with std module. A furhter step would be to get all the test programs and examples to build as well. I could do this as a follow up PR or include it in this one although that will obviously make the diff bigger.

Anyway let me know how you feel or if you have any suggestions.

@davidhunter22
Copy link
Contributor Author

BTW including the type_safe headers with /std::latest does give a few warnings

'std::aligned_storage<4,4>': warning STL4034: std::aligned_storage and std::aligned_storage_t are deprecated in C++23. Prefer alignas(T) std::byte t_buff[sizeof(T)].

Also the code is at https://github.com/davidhunter22/type_safe/tree/std_module

@foonathan
Copy link
Owner

I'm happy for any and all PRs.

The main changes are [...]

Sounds good. Please split bugfixes and compiler workaround into separate PRs.

A furhter step would be to get all the test programs and examples to build as well. I could do this as a follow up PR or include it in this one although that will obviously make the diff bigger.

Let's focus on things affecting end users first.

BTW including the type_safe headers with /std::latest does give a few warnings

Right, these should be replaced by alignas + char array. Can you do a separate PR for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants