init cpp repo
This commit is contained in:
commit
88b32bd3f0
8 changed files with 273 additions and 0 deletions
4
.clang-format
Normal file
4
.clang-format
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: Google
|
||||
...
|
||||
28
.clangd
Normal file
28
.clangd
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Xclang
|
||||
- -fno-validate-pch
|
||||
- -fretain-comments-from-system-headers
|
||||
Compiler: clang++
|
||||
Index:
|
||||
Background: true
|
||||
Diagnostics:
|
||||
ClangTidy:
|
||||
Add:
|
||||
- modernize-*
|
||||
- performance-*
|
||||
- cppcoreguidelines-*
|
||||
ClangTidyChecks: true
|
||||
Options:
|
||||
UseChecks:
|
||||
- "*"
|
||||
WarningAsErrors: cppcoreguidelines-*
|
||||
InlayHints:
|
||||
Enabled: true
|
||||
ParameterNames: true
|
||||
DeducedTypes: true
|
||||
Designators: true
|
||||
Completion:
|
||||
AllScopes: true
|
||||
SemanticTokens:
|
||||
Enabled: true
|
||||
3
.envrc
Normal file
3
.envrc
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
watch_file ./flake.*
|
||||
|
||||
use flake
|
||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
/.direnv/
|
||||
/build/
|
||||
/.cache/
|
||||
/compile_commands.json
|
||||
26
Makefile
Normal file
26
Makefile
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
.RECIPEPREFIX = >
|
||||
.DEFAULT_GOAL = build/main.out
|
||||
CXX = clang++
|
||||
CXXFLAGS += -std=c++26 -Wno-experimental-header-units
|
||||
LDFLAGS += -std=c++26
|
||||
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)))
|
||||
|
||||
build/main.out: build/main.o
|
||||
> $(CXX) $(LDFLAGS) $^ -o $@
|
||||
|
||||
build/main.o: main.cxx build/print.pcm build/type_traits.pcm
|
||||
> $(CXX) $(CXXFLAGS) -c $(filter-out %.pcm,$^) $(call build_module_path,$(filter %.pcm,$^))
|
||||
> @mv $(patsubst build/%,%,$@) $@
|
||||
|
||||
build/%.pcm:
|
||||
> $(CXX) $(CXXFLAGS) -xc++-system-header --precompile $(patsubst build/%.pcm,%,$@) -o $@ $(SYSTEMHEADER_FLAGS)
|
||||
|
||||
.PHONY: clean run
|
||||
clean:
|
||||
> @-rm -rf ./build/*
|
||||
bear: clean
|
||||
> bear -- $(MAKE)
|
||||
|
||||
run: $(.DEFAULT_GOAL)
|
||||
> @./$(.DEFAULT_GOAL)
|
||||
94
flake.lock
generated
Normal file
94
flake.lock
generated
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "flake-utils",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1745377448,
|
||||
"narHash": "sha256-jhZDfXVKdD7TSEGgzFJQvEEZ2K65UMiqW5YJ2aIqxMA=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "507b63021ada5fee621b6ca371c4fca9ca46f52c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-cmake": {
|
||||
"locked": {
|
||||
"lastModified": 1745570837,
|
||||
"narHash": "sha256-8MwKbng4lvA5wgBbOx0+VohonuMnUd62xJ6gE4tdXdU=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "ceecbb5d1184da5866a824b7accbb4a8c07a73eb",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "pull/394444/head",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-gcc15": {
|
||||
"locked": {
|
||||
"lastModified": 1745644951,
|
||||
"narHash": "sha256-Rqnc3VvR2T6vJ2JwXhX6h9zwSYjWITk3YdOUKcCM284=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "281c0c16c9c6e2e44e78334f55bbd43dc51c0d70",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "pull/401948/head",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"nixpkgs-cmake": "nixpkgs-cmake",
|
||||
"nixpkgs-gcc15": "nixpkgs-gcc15"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
60
flake.nix
Normal file
60
flake.nix
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
nixpkgs-gcc15.url = "github:NixOS/nixpkgs/?ref=pull/401948/head";
|
||||
nixpkgs-cmake.url = "github:NixOS/nixpkgs/?ref=pull/394444/head";
|
||||
};
|
||||
outputs = {
|
||||
nixpkgs-cmake,
|
||||
nixpkgs-gcc15,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system: let
|
||||
inherit
|
||||
(import nixpkgs-cmake {
|
||||
inherit system;
|
||||
config = {
|
||||
cudaSupport = true;
|
||||
};
|
||||
})
|
||||
cmake
|
||||
;
|
||||
inherit
|
||||
(import nixpkgs-gcc15 {
|
||||
inherit system;
|
||||
config = {
|
||||
cudaSupport = true;
|
||||
};
|
||||
})
|
||||
gcc15
|
||||
gcc15Stdenv
|
||||
;
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
config = {
|
||||
cudaSupport = true;
|
||||
};
|
||||
};
|
||||
in {
|
||||
devShells.default =
|
||||
pkgs.mkShell.override
|
||||
{
|
||||
stdenv = pkgs.llvmPackages_20.libcxxStdenv;
|
||||
# stdenv = gcc15Stdenv;
|
||||
}
|
||||
{
|
||||
packages = with pkgs; [
|
||||
llvmPackages_20.clang-tools
|
||||
gnumake
|
||||
llvmPackages_20.clang
|
||||
bear
|
||||
# cmake
|
||||
# gcc15
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
54
main.cxx
Normal file
54
main.cxx
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import <print>;
|
||||
import <type_traits>;
|
||||
|
||||
template <bool param1 = false, bool param2 = false>
|
||||
struct Builder;
|
||||
template <bool enabled>
|
||||
struct BuildMixin {};
|
||||
|
||||
template <>
|
||||
struct BuildMixin<true> {
|
||||
auto build(this auto&& self) { return self.p1 + self.p2; }
|
||||
};
|
||||
|
||||
template <bool enabled>
|
||||
struct Param1Mixin {};
|
||||
|
||||
template <>
|
||||
struct Param1Mixin<false> {
|
||||
auto fill_param1(this auto&& self) {
|
||||
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) {
|
||||
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 {
|
||||
Builder builder;
|
||||
auto ret = builder.fill_param1().fill_param2().build();
|
||||
std::println("{}", ret);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue