Skip to content

C++20 compatible polyfill for <expected> #1032

C++20 compatible polyfill for <expected>

C++20 compatible polyfill for <expected> #1032

Workflow file for this run

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:
linux-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
linux-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
macos-cxx23:
runs-on: macos-${{ matrix.env.osver }}
strategy:
fail-fast: false
matrix:
configuration:
- Debug
- Release
env:
- compiler: clang++
osver: 15
- compiler: "$(brew --prefix llvm@18)/bin/clang++"
osver: 15
steps:
- uses: actions/checkout@v4
- name: Prepare build
run: |
mkdir .build
cd .build
cmake -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DCMAKE_CXX_COMPILER=${{ matrix.env.compiler }} ..
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 cxx23
- name: Run tests
run: |
cd .build
ctest -L cxx23 -C ${{ matrix.configuration }} --output-on-failure
macos-cxx20:
runs-on: macos-${{ matrix.env.osver }}
strategy:
fail-fast: false
matrix:
configuration:
- Debug
- Release
env:
- compiler: clang++
osver: 15
- compiler: "$(brew --prefix llvm@18)/bin/clang++"
osver: 15
steps:
- uses: actions/checkout@v4
- name: Prepare build
run: |
mkdir .build
cd .build
cmake -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DCMAKE_CXX_COMPILER=${{ matrix.env.compiler }} ..
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 -C ${{ matrix.configuration }} --output-on-failure
windows-cxx20:
runs-on: windows-${{ matrix.env.osver }}
strategy:
fail-fast: false
matrix:
configuration:
- Debug
- Release
env:
- vsver: "Visual Studio 17 2022"
osver: 2025
- vsver: "Visual Studio 17 2022"
osver: 2022
- vsver: "Visual Studio 17 2022"
osver: 2019
steps:
- uses: actions/checkout@v4
- name: Prepare build
run: |
mkdir .build
cd .build
cmake -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -G "${{ matrix.env.vsver }}" -A x64 ..
- name: Build all
run: |
cd .build
cmake --build . --target cxx20
- name: Run tests
run: |
cd .build
ctest -L cxx20 -C ${{ matrix.configuration }} --output-on-failure