use divided module
This commit is contained in:
		
							parent
							
								
									0017c36e2f
								
							
						
					
					
						commit
						aba9ddc048
					
				
					 7 changed files with 138 additions and 74 deletions
				
			
		
							
								
								
									
										10
									
								
								.clangd
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								.clangd
									
										
									
									
									
								
							|  | @ -1,22 +1,16 @@ | ||||||
| CompileFlags: | CompileFlags: | ||||||
|   Add: |   Add: | ||||||
|  |     - -std=c++26 | ||||||
|     - -Xclang |     - -Xclang | ||||||
|     - -fno-validate-pch |     - -fno-validate-pch | ||||||
|     - -fretain-comments-from-system-headers |     - -fretain-comments-from-system-headers | ||||||
|   Compiler: clang++ |   Compiler: clang++ | ||||||
| Index: |  | ||||||
|   Background: true |  | ||||||
| Diagnostics: | Diagnostics: | ||||||
|   ClangTidy: |   ClangTidy: | ||||||
|     Add: |     Add: | ||||||
|       - modernize-* |       - modernize-* | ||||||
|       - performance-* |       - performance-* | ||||||
|       - cppcoreguidelines-* |       - cppcoreguidelines-* | ||||||
|     ClangTidyChecks: true |  | ||||||
|     Options: |  | ||||||
|       UseChecks: |  | ||||||
|         - "*" |  | ||||||
|       WarningAsErrors: cppcoreguidelines-* |  | ||||||
| InlayHints: | InlayHints: | ||||||
|   Enabled: true |   Enabled: true | ||||||
|   ParameterNames: true |   ParameterNames: true | ||||||
|  | @ -24,5 +18,3 @@ InlayHints: | ||||||
|   Designators: true |   Designators: true | ||||||
| Completion: | Completion: | ||||||
|   AllScopes: true |   AllScopes: true | ||||||
| SemanticTokens: |  | ||||||
|   Enabled: true |  | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -1,4 +1,3 @@ | ||||||
| /.direnv/ | /.direnv/ | ||||||
| /build/ | /build/ | ||||||
| /.cache/ | /.cache/ | ||||||
| /compile_commands.json |  | ||||||
|  |  | ||||||
							
								
								
									
										28
									
								
								.helix/languages.toml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								.helix/languages.toml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,28 @@ | ||||||
|  | [[language]] | ||||||
|  | name = "cpp" | ||||||
|  | file-types = [ | ||||||
|  |   "cc", | ||||||
|  |   "hh", | ||||||
|  |   "c++", | ||||||
|  |   "cpp", | ||||||
|  |   "hpp", | ||||||
|  |   "h", | ||||||
|  |   "ipp", | ||||||
|  |   "tpp", | ||||||
|  |   "cxx", | ||||||
|  |   "hxx", | ||||||
|  |   "ixx", | ||||||
|  |   "txx", | ||||||
|  |   "ino", | ||||||
|  |   "C", | ||||||
|  |   "H", | ||||||
|  |   "cu", | ||||||
|  |   "cuh", | ||||||
|  |   "cppm", | ||||||
|  |   "cxxm", | ||||||
|  |   "h++", | ||||||
|  |   "ii", | ||||||
|  |   "inl", | ||||||
|  |   { glob = ".hpp.in" }, | ||||||
|  |   { glob = ".h.in" }, | ||||||
|  | ] | ||||||
							
								
								
									
										32
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										32
									
								
								Makefile
									
										
									
									
									
								
							|  | @ -1,26 +1,40 @@ | ||||||
| .RECIPEPREFIX = > | .RECIPEPREFIX = > | ||||||
| .DEFAULT_GOAL = build/main.out | .DEFAULT_GOAL = build/main.out | ||||||
| CXX = clang++ | CXX = clang++ | ||||||
| CXXFLAGS += -std=c++26 -Wno-experimental-header-units | CXXFLAGS += -std=c++26 -Wno-experimental-header-units -Wno-unused-command-line-argument | ||||||
| LDFLAGS += -std=c++26 | LDFLAGS += -std=c++26 | ||||||
| SYSTEMHEADER_FLAGS = -Wno-deprecated-builtins -Wno-pragma-system-header-outside-header -Wno-keyword-compat | SYSTEMHEADER_FLAGS = -Wno-deprecated-builtins -Wno-pragma-system-header-outside-header -Wno-keyword-compat | ||||||
| build_module_path = $(let first rest,$1,$(if $(rest),-fmodule-file=$(first) $(call build_module_path,$(rest)),-fmodule-file=$(first))) | module_pair = $(if $(findstring user,$1),$(patsubst build/user/%.pcm,%=,$1))$1 | ||||||
|  | build_module_path = $(if $1,$(let first rest,$1,$(if $(rest),-fmodule-file=$(call module_pair,$(first)) $(call build_module_path,$(rest)),-fmodule-file=$(call module_pair,$(first))))) | ||||||
|  | object_build = $(filter-out %.pcm,$^) $(call build_module_path,$(filter %.pcm,$^)) | ||||||
|  | autodir = @mkdir -p $(@D) | ||||||
| 
 | 
 | ||||||
| build/main.out: build/main.o | build/main.out: build/main.o build/builder.o | ||||||
|  | > $(call autodir) | ||||||
| > $(CXX) $(LDFLAGS) $^ -o $@ | > $(CXX) $(LDFLAGS) $^ -o $@ | ||||||
| 
 | 
 | ||||||
| build/main.o: main.cxx build/print.pcm build/type_traits.pcm | build/main.o:: main.cxx build/system/print.pcm build/user/builder.pcm | ||||||
| > $(CXX) $(CXXFLAGS) -c $(filter-out %.pcm,$^) $(call build_module_path,$(filter %.pcm,$^)) | build/builder.o:: builder.cxxm build/system/type_traits.pcm | ||||||
|  | build/user/builder.pcm:: build/system/type_traits.pcm | ||||||
|  | 
 | ||||||
|  | build/%.o:: | ||||||
|  | > $(call autodir) | ||||||
|  | > $(CXX) $(CXXFLAGS) -c $(call object_build) | ||||||
| > @mv $(patsubst build/%,%,$@) $@ | > @mv $(patsubst build/%,%,$@) $@ | ||||||
| 
 | 
 | ||||||
| build/%.pcm: | build/user/%.pcm:: %.cxxm | ||||||
| > $(CXX) $(CXXFLAGS) -xc++-system-header --precompile $(patsubst build/%.pcm,%,$@) -o $@ $(SYSTEMHEADER_FLAGS) | > $(call autodir) | ||||||
|  | > $(CXX) $(CXXFLAGS) --precompile -o $@ $(call object_build) | ||||||
|  | 
 | ||||||
|  | build/system/%.pcm: | ||||||
|  | > $(call autodir) | ||||||
|  | > $(CXX) $(CXXFLAGS) -xc++-system-header --precompile $(patsubst build/system/%.pcm,%,$@) -o $@ $(SYSTEMHEADER_FLAGS) | ||||||
| 
 | 
 | ||||||
| .PHONY: clean run | .PHONY: clean run | ||||||
| clean: | clean: | ||||||
| > @-rm -rf ./build/* | > @-rm -rf ./build | ||||||
| bear: clean | bear: clean | ||||||
| > bear -- $(MAKE) | > bear --append -- $(MAKE) | ||||||
| 
 | 
 | ||||||
| run: $(.DEFAULT_GOAL) | run: $(.DEFAULT_GOAL) | ||||||
| > @./$(.DEFAULT_GOAL) | > @./$(.DEFAULT_GOAL) | ||||||
|  |  | ||||||
							
								
								
									
										56
									
								
								builder.cxxm
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								builder.cxxm
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,56 @@ | ||||||
|  | export module builder; | ||||||
|  | import <type_traits>; | ||||||
|  | 
 | ||||||
|  | export template <bool param1 = false, bool param2 = false> | ||||||
|  | struct Builder; | ||||||
|  | template <bool enabled> | ||||||
|  | struct BuildMixin {}; | ||||||
|  | 
 | ||||||
|  | template <> | ||||||
|  | struct BuildMixin<true> { | ||||||
|  |   auto build(this auto&& self) | ||||||
|  |     requires requires { self.p1 + self.p2; } | ||||||
|  |   { | ||||||
|  |     return self.p1 + self.p2; | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | template <bool enabled> | ||||||
|  | struct Param1Mixin {}; | ||||||
|  | 
 | ||||||
|  | template <> | ||||||
|  | struct Param1Mixin<false> { | ||||||
|  |   auto fill_param1(this auto&& self) | ||||||
|  |     requires requires { self.p1; } | ||||||
|  |   { | ||||||
|  |     self.p1 = 1; | ||||||
|  |     return Builder<true, std::remove_reference_t<decltype(self)>::param2_v>( | ||||||
|  |         self); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | template <bool enabled> | ||||||
|  | struct Param2Mixin {}; | ||||||
|  | 
 | ||||||
|  | template <> | ||||||
|  | struct Param2Mixin<false> { | ||||||
|  |   auto fill_param2(this auto&& self) | ||||||
|  |     requires requires { self.p2; } | ||||||
|  |   { | ||||||
|  |     self.p2 = 1; | ||||||
|  |     return Builder<std::remove_reference_t<decltype(self)>::param1_v, true>( | ||||||
|  |         self); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | template <bool param1, bool param2> | ||||||
|  | struct Builder : BuildMixin<param1 && param2>, | ||||||
|  |                  Param1Mixin<param1>, | ||||||
|  |                  Param2Mixin<param2> { | ||||||
|  |   const constinit static auto param1_v = param1; | ||||||
|  |   const constinit static auto param2_v = param2; | ||||||
|  |   int p1; | ||||||
|  |   int p2; | ||||||
|  |   Builder() : p1(0), p2(0) {} | ||||||
|  |   Builder(auto&& other) : p1(other.p1), p2(other.p2) {} | ||||||
|  | }; | ||||||
							
								
								
									
										29
									
								
								compile_commands.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								compile_commands.json
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,29 @@ | ||||||
|  | [ | ||||||
|  |   { | ||||||
|  |     "arguments": [ | ||||||
|  |       "/nix/store/k50vj1b6vpz84n88vk09gxsgcyqrg00m-clang-wrapper-20.1.3/bin/clang++", | ||||||
|  |       "-std=c++26", | ||||||
|  |       "-Wno-experimental-header-units", | ||||||
|  |       "-Wno-unused-command-line-argument", | ||||||
|  |       "-c", | ||||||
|  |       "-fmodule-file=build/system/print.pcm", | ||||||
|  |       "-fmodule-file=builder=build/user/builder.pcm", | ||||||
|  |       "main.cxx" | ||||||
|  |     ], | ||||||
|  |     "directory": "/home/david/code/cxx", | ||||||
|  |     "file": "/home/david/code/cxx/main.cxx" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |     "arguments": [ | ||||||
|  |       "/nix/store/k50vj1b6vpz84n88vk09gxsgcyqrg00m-clang-wrapper-20.1.3/bin/clang++", | ||||||
|  |       "-std=c++26", | ||||||
|  |       "-Wno-experimental-header-units", | ||||||
|  |       "-Wno-unused-command-line-argument", | ||||||
|  |       "-c", | ||||||
|  |       "-fmodule-file=build/system/type_traits.pcm", | ||||||
|  |       "builder.cxxm" | ||||||
|  |     ], | ||||||
|  |     "directory": "/home/david/code/cxx", | ||||||
|  |     "file": "/home/david/code/cxx/builder.cxxm" | ||||||
|  |   } | ||||||
|  | ] | ||||||
							
								
								
									
										56
									
								
								main.cxx
									
										
									
									
									
								
							
							
						
						
									
										56
									
								
								main.cxx
									
										
									
									
									
								
							|  | @ -1,59 +1,5 @@ | ||||||
| import <print>; | import <print>; | ||||||
| import <type_traits>; | import builder; | ||||||
| 
 |  | ||||||
| template <bool param1 = false, bool param2 = false> |  | ||||||
| struct Builder; |  | ||||||
| template <bool enabled> |  | ||||||
| struct BuildMixin {}; |  | ||||||
| 
 |  | ||||||
| template <> |  | ||||||
| struct BuildMixin<true> { |  | ||||||
|   auto build(this auto&& self) |  | ||||||
|     requires requires { self.p1 + self.p2; } |  | ||||||
|   { |  | ||||||
|     return self.p1 + self.p2; |  | ||||||
|   } |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| template <bool enabled> |  | ||||||
| struct Param1Mixin {}; |  | ||||||
| 
 |  | ||||||
| template <> |  | ||||||
| struct Param1Mixin<false> { |  | ||||||
|   auto fill_param1(this auto&& self) |  | ||||||
|     requires requires { self.p1; } |  | ||||||
|   { |  | ||||||
|     self.p1 = 1; |  | ||||||
|     return Builder<true, std::remove_reference_t<decltype(self)>::param2_v>( |  | ||||||
|         self); |  | ||||||
|   } |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| template <bool enabled> |  | ||||||
| struct Param2Mixin {}; |  | ||||||
| 
 |  | ||||||
| template <> |  | ||||||
| struct Param2Mixin<false> { |  | ||||||
|   auto fill_param2(this auto&& self) |  | ||||||
|     requires requires { self.p2; } |  | ||||||
|   { |  | ||||||
|     self.p2 = 1; |  | ||||||
|     return Builder<std::remove_reference_t<decltype(self)>::param1_v, true>( |  | ||||||
|         self); |  | ||||||
|   } |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| template <bool param1, bool param2> |  | ||||||
| struct Builder : BuildMixin<param1 && param2>, |  | ||||||
|                  Param1Mixin<param1>, |  | ||||||
|                  Param2Mixin<param2> { |  | ||||||
|   const constinit static auto param1_v = param1; |  | ||||||
|   const constinit static auto param2_v = param2; |  | ||||||
|   int p1; |  | ||||||
|   int p2; |  | ||||||
|   Builder() : p1(0), p2(0) {} |  | ||||||
|   Builder(auto&& other) : p1(other.p1), p2(other.p2) {} |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| auto main() -> int { | auto main() -> int { | ||||||
|   Builder builder; |   Builder builder; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue