diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 61c92db..9c4260d 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -31,21 +31,18 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Cache apt packages - uses: actions/cache@v3 - with: - path: /var/cache/apt/archives - key: ${{ runner.os }}-apt-${{ hashFiles('**/CMakeLists.txt') }} - restore-keys: | - ${{ runner.os }}-apt- - - - name: Install dependencies (Linux) - if: runner.os == 'Linux' + - name: Install dependencies + shell: bash run: | - sudo apt-get update - sudo apt-get install -y cmake ninja-build build-essential - if [[ "${{ matrix.c_compiler }}" == "clang" ]]; then - sudo apt-get install -y clang lld + if [[ "${{ runner.os }}" == "Linux" ]]; then + sudo apt-get update + sudo apt-get install -y cmake ninja-build build-essential + if [[ "${{ matrix.c_compiler }}" == "clang" ]]; then + sudo apt-get install -y clang lld + fi + elif [[ "${{ runner.os }}" == "Windows" ]]; then + choco install cmake --installargs '"ADD_CMAKE_TO_PATH=System"' -y + choco install ninja -y fi - name: Cache CMake files @@ -63,24 +60,37 @@ jobs: id: strings shell: bash run: | - echo "build-output-dir=${GITHUB_WORKSPACE}/build" >> "$GITHUB_OUTPUT" + if [[ "${{ runner.os }}" == "Linux" ]]; then + echo "build-output-dir=${GITHUB_WORKSPACE}/build" >> "$GITHUB_OUTPUT" + elif [[ "${{ runner.os }}" == "Windows" ]]; then + echo "build-output-dir=${GITHUB_WORKSPACE}\build" >> "$GITHUB_OUTPUT" + fi - name: Create build directory run: cmake -E make_directory ${{ steps.strings.outputs.build-output-dir }} - - name: Configure CMake (Linux) - if: runner.os == 'Linux' + - name: Configure CMake + shell: bash run: | - cmake -B ${{ steps.strings.outputs.build-output-dir }} \ - -DCMAKE_CXX_STANDARD=20 \ - -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \ - -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \ - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ - -G Ninja \ - -S ${{ github.workspace }} + if [[ "${{ runner.os }}" == "Linux" ]]; then + cmake -B "${{ steps.strings.outputs.build-output-dir }}" \ + -DCMAKE_CXX_STANDARD=20 \ + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \ + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \ + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + -G Ninja \ + -S ${{ github.workspace }} + elif [[ "${{ runner.os }}" == "Windows" ]]; then + cmake -B "${{ steps.strings.outputs.build-output-dir }}" \ + -DCMAKE_CXX_STANDARD=20 \ + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + -G Ninja \ + -A x64 \ + -S ${{ github.workspace }} + fi - name: Cache build - uses: actions/cache@v3 + uses: actions/cache@v31 with: path: ${{ github.workspace }}/build key: ${{ runner.os }}-build-${{ hashFiles('**/*.cpp', '**/*.hpp', '**/*.h') }} @@ -96,14 +106,24 @@ jobs: - name: Run tests working-directory: ${{ steps.strings.outputs.build-output-dir }} - run: ./tests + run: | + if [[ "${{ runner.os }}" == "Windows" ]]; then + .\tests.exe + else + ./tests + fi - name: Run benchmarks working-directory: ${{ steps.strings.outputs.build-output-dir }} - run: ./measure --benchmark_format=console --benchmark_out=benchmark_results.json + run: | + if [[ "${{ runner.os }}" == "Windows" ]]; then + .\measure.exe --benchmark_format=console --benchmark_out=benchmark_results.json + else + ./measure --benchmark_format=console --benchmark_out=benchmark_results.json + fi - name: Upload benchmark results uses: actions/upload-artifact@v4 with: - name: benchmark-results - path: benchmark_results.json + name: benchmark-results + path: benchmark_results.json \ No newline at end of file diff --git a/fastcast.hpp b/fastcast.hpp index c5c27df..1f6db60 100644 --- a/fastcast.hpp +++ b/fastcast.hpp @@ -18,11 +18,9 @@ #define CONSTEXPR #endif - namespace fastcast { -// Core implementation for pointer types -template CONSTEXPR inline To cast_impl(From *ptr) { +template CONSTEXPR inline To fast_cast_impl(From *ptr) { using v_table_ptr = const uintptr_t *; if constexpr (std::is_same_v, std::remove_pointer_t>) { @@ -76,7 +74,7 @@ constexpr inline To fast_cast(From *ptr) { using ToNonPtr = std::remove_pointer_t; using ToPtr = std::conditional_t, const ToNonPtr *, ToNonPtr *>; - return cast_impl(ptr); + return fast_cast_impl(ptr); } // Reference overload