C++20 compatible polyfill for <expected>
#1024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - '.github/workflows/build.yml' | |
| - 'include/**' | |
| - 'tests/**' | |
| - 'CMakeLists.txt' | |
| - 'cmake/**' | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - '.github/workflows/build.yml' | |
| - 'include/**' | |
| - 'tests/**' | |
| - 'CMakeLists.txt' | |
| - 'cmake/**' | |
| jobs: | |
| build-cxx23: | |
| runs-on: | |
| group: default | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| configuration: | |
| - Debug | |
| - Release | |
| compiler: | |
| - gcc:13 | |
| - gcc:14 | |
| - clang:18 | |
| - clang:19 | |
| container: libfn/ci-build-${{ matrix.compiler }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Verify compiler compatibility | |
| env: | |
| SOURCE: | | |
| #include <optional> | |
| #include <expected> | |
| #include <cstdio> | |
| int main() { | |
| using type1=std::expected<int, const char*>; | |
| using type2=std::optional<int>; | |
| return type1{1}.and_then([](int i) -> type1 { std::puts("OK expected"); return {i-1}; }).value() | |
| + type2{2}.and_then([](int i) -> type2 { std::puts("OK optional"); return {i-2}; }).value(); | |
| } | |
| run: | | |
| printf "CXX=%s\nCXXFLAGS=%s\n" "$CXX" "$CXXFLAGS" | |
| $CXX --version | head -1 | |
| FILE=$(mktemp --tmpdir XXXXXX.cpp) | |
| printf "$SOURCE\n" > $FILE | |
| OUT=$(mktemp --tmpdir XXXXXX) | |
| $CXX -std=c++2b $CXXFLAGS -Wall $FILE -o $OUT | |
| $OUT | |
| - name: Prepare build | |
| run: | | |
| mkdir .build | |
| cd .build | |
| cmake -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} .. | |
| COMPILER=$( grep -E "^CMAKE_CXX_COMPILER:FILEPATH=" CMakeCache.txt | sed -e "s|^[^=]*=||" ) | |
| FLAGS=$( grep -iE "^CMAKE_CXX_FLAGS:STRING=" CMakeCache.txt | sed -e "s|^[^=]*=||" ) | |
| printf "C++ compiler: %s\n" "$COMPILER" | |
| printf "C++ compiler version: %s\n" "$( $COMPILER --version | head -1 )" | |
| printf "C++ compilation options: %s\n" "$FLAGS" | |
| - name: Build all | |
| env: | |
| # We want to build "--target all" for at least one arbitrary configuration | |
| TARGET: ${{ ( matrix.configuration == 'Debug' && matrix.compiler == 'gcc:14' ) && 'all' || 'cxx23' }} | |
| run: | | |
| cd .build | |
| cmake --build . --target ${TARGET} | |
| - name: Run tests | |
| run: | | |
| cd .build | |
| ctest -L cxx23 --output-on-failure | |
| build-cxx20: | |
| runs-on: | |
| group: default | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| configuration: | |
| - Debug | |
| - Release | |
| compiler: | |
| - gcc:12 | |
| - gcc:13 | |
| - gcc:14 | |
| - clang:16 | |
| - clang:17 | |
| - clang:18 | |
| - clang:19 | |
| container: libfn/ci-build-${{ matrix.compiler }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Verify compiler compatibility | |
| env: | |
| SOURCE: | | |
| #include <optional> | |
| int main() { | |
| using type=std::optional<int>; | |
| constexpr type a{std::in_place, 1}; | |
| return a.value() - 1; | |
| } | |
| run: | | |
| printf "CXX=%s\nCXXFLAGS=%s\n" "$CXX" "$CXXFLAGS" | |
| $CXX --version | head -1 | |
| FILE=$(mktemp --tmpdir XXXXXX.cpp) | |
| printf "$SOURCE\n" > $FILE | |
| OUT=$(mktemp --tmpdir XXXXXX) | |
| $CXX -std=c++2a $CXXFLAGS -Wall $FILE -o $OUT | |
| $OUT | |
| - name: Prepare build | |
| run: | | |
| mkdir .build | |
| cd .build | |
| cmake -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} .. | |
| COMPILER=$( grep -E "^CMAKE_CXX_COMPILER:FILEPATH=" CMakeCache.txt | sed -e "s|^[^=]*=||" ) | |
| FLAGS=$( grep -iE "^CMAKE_CXX_FLAGS:STRING=" CMakeCache.txt | sed -e "s|^[^=]*=||" ) | |
| printf "C++ compiler: %s\n" "$COMPILER" | |
| printf "C++ compiler version: %s\n" "$( $COMPILER --version | head -1 )" | |
| printf "C++ compilation options: %s\n" "$FLAGS" | |
| - name: Build all | |
| run: | | |
| cd .build | |
| cmake --build . --target cxx20 | |
| - name: Run tests | |
| run: | | |
| cd .build | |
| ctest -L cxx20 --output-on-failure |