Skip to content

Commit 37abed8

Browse files
authored
Merge pull request #3 from bemanproject/fix-ci
Fix format + Make project buildable
2 parents a30545a + 478754e commit 37abed8

File tree

11 files changed

+62
-73
lines changed

11 files changed

+62
-73
lines changed

CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.25)
44

55
project(beman.scope DESCRIPTION "Generic Scope Guard" LANGUAGES CXX)
66

7-
# enable_testing()
7+
enable_testing()
88

99
# [CMAKE.SKIP_TESTS]
1010
option(
@@ -20,14 +20,13 @@ option(
2020
${PROJECT_IS_TOP_LEVEL}
2121
)
2222

23-
include(FetchContent)
2423
include(GNUInstallDirs)
2524

26-
# add_subdirectory(src/beman/scope)
25+
add_subdirectory(src/beman/scope)
2726

28-
#if(BEMAN_SCOPE_BUILD_TESTS)
29-
# add_subdirectory(tests/beman/scope)
30-
#endif()
27+
if(BEMAN_SCOPE_BUILD_TESTS)
28+
add_subdirectory(tests/beman/scope)
29+
endif()
3130

3231
if(BEMAN_SCOPE_BUILD_EXAMPLES)
3332
add_subdirectory(examples)

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1010

1111
# Overview
1212

13-
During the C++20 cycle [P0052 Generic Scope Guard and RAII Wrapper for the Standard Library](https://wg21.link/P0052) added 4 types: `scope_exit`, `scope_fail`, `scope_success` and `unique_resource` to [LTFSv3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4908#scopeguard). In the intervening time, two standard libraries have implemented support as well as Boost. With the imperative for safety and security in C++ developers need every tool in the toolbox. The authors believe it is time to move this facility into the standard. The paper will re-examine the five year old design and any learning from deployment of the LTFSv3.
13+
During the C++20 cycle [P0052 Generic Scope Guard and RAII Wrapper for the Standard Library](https://wg21.link/P0052)
14+
added 4 types: `scope_exit`, `scope_fail`, `scope_success`
15+
and `unique_resource` to [LTFSv3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4908#scopeguard).
16+
In the intervening time, two standard libraries have implemented support as well as Boost.
17+
With the imperative for safety and security in C++ developers need every tool in the toolbox.
18+
The authors believe it is time to move this facility into the standard.
19+
The paper will re-examine the five year old design and any learning from deployment of the LTFSv3.
1420

1521
For discussions of this library see:
1622

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ message("Examples to be built: ${ALL_EXAMPLES}")
77
foreach(example ${ALL_EXAMPLES})
88
add_executable(beman.scope.examples.${example})
99
target_sources(beman.scope.examples.${example} PRIVATE ${example}.cpp)
10+
target_link_libraries(beman.scope.examples.${example} beman::scope)
1011
endforeach()

examples/scope_example.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3+
#include <beman/scope/scope.hpp>
4+
35
#include <cstdlib>
4-
#include <experimental/scope>
56
#include <iostream>
67
#include <string_view>
78

9+
namespace scope = beman::scope;
10+
811
void print_exit_status(std::string_view name, bool exit_status, bool did_throw) {
912
std::cout << name << ":\n";
1013
std::cout << " Throwed exception " << (did_throw ? "yes" : "no") << "\n";
@@ -32,7 +35,7 @@ int main() {
3235
// Using scope_exit: runs on scope exit (success or exception)
3336
exit_status = did_throw = false;
3437
try {
35-
auto guard = std::experimental::scope_exit{[&] { exit_status = true; }};
38+
auto guard = scope::scope_exit{[&] { exit_status = true; }};
3639
maybe_throw();
3740
} catch (...) {
3841
did_throw = true;
@@ -42,7 +45,7 @@ int main() {
4245
// Using scope_fail: runs only if an exception occurs
4346
exit_status = did_throw = false;
4447
try {
45-
auto guard = std::experimental::scope_fail{[&] { exit_status = true; }};
48+
auto guard = scope::scope_fail{[&] { exit_status = true; }};
4649
maybe_throw();
4750
} catch (...) {
4851
did_throw = true;
@@ -52,7 +55,7 @@ int main() {
5255
// Using scope_success: runs only if no exception occurs
5356
exit_status = did_throw = false;
5457
try {
55-
auto guard = std::experimental::scope_success{[&] { exit_status = true; }};
58+
auto guard = scope::scope_success{[&] { exit_status = true; }};
5659
maybe_throw();
5760
} catch (...) {
5861
did_throw = true;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
int main()
4-
{}
3+
int main() {}

include/beman/scope/scope.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,33 @@ namespace beman::scope {
9393
// template <typename R, typename D>
9494
// unique_resource(R, D) -> unique_resource<R, D>;
9595

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+
96123
} // namespace beman::scope
97124

98125
#endif // BEMAN_SCOPE_HPP

src/beman/scope/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
add_library(beman.scope)
44
add_library(beman::scope ALIAS beman.scope)
55

6-
target_sources(beman.scope PRIVATE identity.cpp)
6+
target_sources(beman.scope PRIVATE scope.cpp)
77

88
target_sources(
99
beman.scope
1010
PUBLIC
1111
FILE_SET HEADERS
1212
BASE_DIRS ${PROJECT_SOURCE_DIR}/include
13-
FILES ${PROJECT_SOURCE_DIR}/include/beman/scope/identity.hpp
13+
FILES ${PROJECT_SOURCE_DIR}/include/beman/scope/scope.hpp
1414
)
1515

1616
set_target_properties(beman.scope PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
#include <beman/scope/identity.hpp>
3+
#include <beman/scope/scope.hpp>

tests/beman/scope/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
#add_executable(beman.scope.tests.identity)
4-
#target_sources(beman.scope.tests.identity PRIVATE identity.test.cpp)
3+
add_executable(beman.scope.tests.scope)
4+
target_sources(beman.scope.tests.scope PRIVATE scope.test.cpp)
5+
6+
target_link_libraries(beman.scope.tests.scope PRIVATE beman::scope)
7+
8+
add_test(NAME beman.scope.tests.scope COMMAND beman.scope.tests.scope)

tests/beman/scope/identity.test.cpp

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)