Skip to content

Commit 41e7e41

Browse files
authored
Merge pull request #12 from bemanproject/using-std-experimental
Delegate implementation to std::experimental
2 parents 37abed8 + c606e1e commit 41e7e41

File tree

2 files changed

+52
-72
lines changed

2 files changed

+52
-72
lines changed

.github/workflows/ci_tests.yml

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ jobs:
2020
platform: "ubuntu-latest"
2121
- preset: "gcc-release"
2222
platform: "ubuntu-latest"
23-
- preset: "appleclang-debug"
24-
platform: "macos-latest"
25-
- preset: "appleclang-release"
26-
platform: "macos-latest"
27-
- preset: "msvc-debug"
28-
platform: "windows-latest"
29-
- preset: "msvc-release"
30-
platform: "windows-latest"
3123
name: "Preset: ${{ matrix.presets.preset }} on ${{ matrix.presets.platform }}"
3224
runs-on: ${{ matrix.presets.platform }}
3325
steps:
@@ -56,13 +48,7 @@ jobs:
5648
- description: "Ubuntu LLVM"
5749
os: ubuntu-latest
5850
toolchain: "cmake/llvm-toolchain.cmake"
59-
- description: "Windows MSVC"
60-
os: windows-latest
61-
toolchain: "cmake/msvc-toolchain.cmake"
62-
- description: "Macos Appleclang"
63-
os: macos-latest
64-
toolchain: "cmake/appleclang-toolchain.cmake"
65-
cpp_version: [17, 20, 23, 26]
51+
cpp_version: [20, 23, 26]
6652
cmake_args:
6753
- description: "Default"
6854
- description: "TSan"
@@ -74,24 +60,18 @@ jobs:
7460
description: "Ubuntu GCC"
7561
os: ubuntu-latest
7662
toolchain: "cmake/gnu-toolchain.cmake"
77-
cpp_version: 17
63+
cpp_version: 20
7864
cmake_args:
7965
description: "Werror"
8066
args: "-DCMAKE_CXX_FLAGS='-Werror=all -Werror=extra'"
8167
- platform:
8268
description: "Ubuntu GCC"
8369
os: ubuntu-latest
8470
toolchain: "cmake/gnu-toolchain.cmake"
85-
cpp_version: 17
71+
cpp_version: 20
8672
cmake_args:
8773
description: "Dynamic"
8874
args: "-DBUILD_SHARED_LIBS=on"
89-
exclude:
90-
# MSVC does not support thread sanitizer
91-
- platform:
92-
description: "Windows MSVC"
93-
cmake_args:
94-
description: "TSan"
9575

9676
name: "Unit: ${{ matrix.platform.description }} ${{ matrix.cpp_version }} ${{ matrix.cmake_args.description }}"
9777
runs-on: ${{ matrix.platform.os }}
@@ -107,6 +87,15 @@ jobs:
10787
uses: TheMrMilchmann/setup-msvc-dev@v3
10888
with:
10989
arch: x64
90+
- name: Setup LLVM
91+
if: matrix.platform.toolchain == 'cmake/llvm-toolchain.cmake'
92+
run: |
93+
wget https://apt.llvm.org/llvm.sh
94+
chmod +x llvm.sh
95+
sudo bash llvm.sh 19
96+
97+
sudo ln -sf "$(which clang-19)" /usr/bin/clang
98+
sudo ln -sf "$(which clang++-19)" /usr/bin/clang++
11099
- name: Setup Macos
111100
if: startsWith(matrix.platform.os, 'macos')
112101
run: sudo chmod -R 777 /opt/
@@ -164,7 +153,7 @@ jobs:
164153
ninja --version
165154
- name: Configure CMake
166155
run: |
167-
cmake -B build -S . -DCMAKE_CXX_STANDARD=17 ${{ matrix.args.arg }}
156+
cmake -B build -S . -DCMAKE_CXX_STANDARD=20 -DCMAKE_TOOLCHAIN_FILE="cmake/gnu-toolchain.cmake" ${{ matrix.args.arg }}
168157
env:
169158
CMAKE_GENERATOR: "Ninja Multi-Config"
170159
- name: Build Release
@@ -190,18 +179,16 @@ jobs:
190179
compilers:
191180
- class: GNU
192181
version: 14
182+
toolchain: "cmake/gnu-toolchain.cmake"
193183
- class: GNU
194184
version: 13
195-
- class: GNU
196-
version: 12
185+
toolchain: "cmake/gnu-toolchain.cmake"
197186
- class: LLVM
198187
version: 20
188+
toolchain: "cmake/llvm-toolchain.cmake"
199189
- class: LLVM
200190
version: 19
201-
- class: LLVM
202-
version: 18
203-
- class: LLVM
204-
version: 17
191+
toolchain: "cmake/llvm-toolchain.cmake"
205192
name: "Compiler: ${{ matrix.compilers.class }} ${{ matrix.compilers.version }}"
206193
steps:
207194
- uses: actions/checkout@v4
@@ -222,8 +209,10 @@ jobs:
222209
sudo apt-get install -y $CC
223210
sudo apt-get install -y $CXX
224211
225-
$CC --version
226-
$CXX --version
212+
sudo ln -sf "$(which $CC)" /usr/bin/gcc
213+
sudo ln -sf "$(which $CXX)" /usr/bin/g++
214+
215+
/usr/bin/g++ --version
227216
else
228217
wget https://apt.llvm.org/llvm.sh
229218
chmod +x llvm.sh
@@ -232,18 +221,15 @@ jobs:
232221
CC=clang-${{ matrix.compilers.version }}
233222
CXX=clang++-${{ matrix.compilers.version }}
234223
235-
$CC --version
236-
$CXX --version
237-
fi
224+
sudo ln -sf "$(which $CC)" /usr/bin/clang
225+
sudo ln -sf "$(which $CXX)" /usr/bin/clang++
238226
239-
echo "CC=$CC" >> "$GITHUB_OUTPUT"
240-
echo "CXX=$CXX" >> "$GITHUB_OUTPUT"
227+
/usr/bin/clang++ --version
228+
fi
241229
- name: Configure CMake
242230
run: |
243-
cmake -B build -S . -DCMAKE_CXX_STANDARD=20
231+
cmake -B build -S . -DCMAKE_CXX_STANDARD=20 -DCMAKE_TOOLCHAIN_FILE="${{ matrix.compilers.toolchain }}"
244232
env:
245-
CC: ${{ steps.install-compiler.outputs.CC }}
246-
CXX: ${{ steps.install-compiler.outputs.CXX }}
247233
CMAKE_GENERATOR: "Ninja Multi-Config"
248234
- name: Build Debug
249235
run: |

include/beman/scope/scope.hpp

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
#ifndef BEMAN_SCOPE_HPP
44
#define BEMAN_SCOPE_HPP
55

6+
#include <type_traits>
7+
#include <utility>
8+
9+
#include <experimental/scope>
10+
611
namespace beman::scope {
712

813
// -- 7.6.7 Feature test macro --
@@ -13,22 +18,39 @@ namespace beman::scope {
1318
// -- 7.5.1 Header <scope> synopsis [scope.syn] --
1419
//
1520
// namespace std {
21+
1622
// template <class EF>
1723
// class scope_exit;
18-
//
24+
template <class EF>
25+
using scope_exit = std::experimental::scope_exit<EF>;
26+
1927
// template <class EF>
2028
// class scope_fail;
21-
//
29+
template <class EF>
30+
using scope_fail = std::experimental::scope_fail<EF>;
31+
2232
// template <class EF>
2333
// class scope_success;
24-
//
34+
template <class EF>
35+
using scope_success = std::experimental::scope_success<EF>;
36+
2537
// template <class R, class D>
2638
// class unique_resource;
27-
//
39+
template <class R, class D>
40+
using unique_resource = std::experimental::unique_resource<R, D>;
41+
2842
// // factory function
2943
// template <class R, class D, class S = decay_t<R>>
3044
// unique_resource<decay_t<R>, decay_t<D>>
3145
// make_unique_resource_checked(R&& r, const S& invalid, D&& d) noexcept(see below);
46+
47+
template <class R, class D, class S = std::decay_t<R>>
48+
unique_resource<std::decay_t<R>, std::decay_t<D>>
49+
make_unique_resource_checked(R&& r, const S& invalid, D&& d) noexcept(noexcept(
50+
std::experimental::make_unique_resource_checked(std::forward(r), std::forward(invalid), std::forward(d)))) {
51+
return std::experimental::make_unique_resource_checked(std::forward(r), std::forward(invalid), std::forward(d));
52+
}
53+
3254
// } // namespace std
3355
//
3456

@@ -59,7 +81,6 @@ namespace beman::scope {
5981
// template <class EF>
6082
// scope_guard(EF) -> scope_guard<EF>;
6183
//
62-
6384
// -- 7.6.1 Class template unique_resource [scope.unique_resource.class] --
6485
//
6586
// template <class R, class D>
@@ -93,33 +114,6 @@ namespace beman::scope {
93114
// template <typename R, typename D>
94115
// unique_resource(R, D) -> unique_resource<R, D>;
95116

96-
// TODO: Implement
97-
struct scope_exit {
98-
template <typename F>
99-
scope_exit(F) {}
100-
~scope_exit() {
101-
// TODO: Cleanup
102-
}
103-
};
104-
105-
// TODO: Implement
106-
struct scope_fail {
107-
template <typename F>
108-
scope_fail(F) {}
109-
~scope_fail() {
110-
// TODO: Cleanup
111-
}
112-
};
113-
114-
// TODO: Implement
115-
struct scope_success {
116-
template <typename F>
117-
scope_success(F) {}
118-
~scope_success() {
119-
// TODO: Cleanup
120-
}
121-
};
122-
123117
} // namespace beman::scope
124118

125119
#endif // BEMAN_SCOPE_HPP

0 commit comments

Comments
 (0)