Skip to content

Commit

Permalink
Merge pull request #3 from bemanproject/fix-ci
Browse files Browse the repository at this point in the history
Fix format + Make project buildable
  • Loading branch information
wusatosi authored Feb 7, 2025
2 parents a30545a + 478754e commit 37abed8
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 73 deletions.
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.25)

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

# enable_testing()
enable_testing()

# [CMAKE.SKIP_TESTS]
option(
Expand All @@ -20,14 +20,13 @@ option(
${PROJECT_IS_TOP_LEVEL}
)

include(FetchContent)
include(GNUInstallDirs)

# add_subdirectory(src/beman/scope)
add_subdirectory(src/beman/scope)

#if(BEMAN_SCOPE_BUILD_TESTS)
# add_subdirectory(tests/beman/scope)
#endif()
if(BEMAN_SCOPE_BUILD_TESTS)
add_subdirectory(tests/beman/scope)
endif()

if(BEMAN_SCOPE_BUILD_EXAMPLES)
add_subdirectory(examples)
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Overview

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.
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.

For discussions of this library see:

Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ message("Examples to be built: ${ALL_EXAMPLES}")
foreach(example ${ALL_EXAMPLES})
add_executable(beman.scope.examples.${example})
target_sources(beman.scope.examples.${example} PRIVATE ${example}.cpp)
target_link_libraries(beman.scope.examples.${example} beman::scope)
endforeach()
11 changes: 7 additions & 4 deletions examples/scope_example.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/scope/scope.hpp>

#include <cstdlib>
#include <experimental/scope>
#include <iostream>
#include <string_view>

namespace scope = beman::scope;

void print_exit_status(std::string_view name, bool exit_status, bool did_throw) {
std::cout << name << ":\n";
std::cout << " Throwed exception " << (did_throw ? "yes" : "no") << "\n";
Expand Down Expand Up @@ -32,7 +35,7 @@ int main() {
// Using scope_exit: runs on scope exit (success or exception)
exit_status = did_throw = false;
try {
auto guard = std::experimental::scope_exit{[&] { exit_status = true; }};
auto guard = scope::scope_exit{[&] { exit_status = true; }};
maybe_throw();
} catch (...) {
did_throw = true;
Expand All @@ -42,7 +45,7 @@ int main() {
// Using scope_fail: runs only if an exception occurs
exit_status = did_throw = false;
try {
auto guard = std::experimental::scope_fail{[&] { exit_status = true; }};
auto guard = scope::scope_fail{[&] { exit_status = true; }};
maybe_throw();
} catch (...) {
did_throw = true;
Expand All @@ -52,7 +55,7 @@ int main() {
// Using scope_success: runs only if no exception occurs
exit_status = did_throw = false;
try {
auto guard = std::experimental::scope_success{[&] { exit_status = true; }};
auto guard = scope::scope_success{[&] { exit_status = true; }};
maybe_throw();
} catch (...) {
did_throw = true;
Expand Down
3 changes: 1 addition & 2 deletions examples/unique_resource_example.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

int main()
{}
int main() {}
27 changes: 27 additions & 0 deletions include/beman/scope/scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@ namespace beman::scope {
// template <typename R, typename D>
// unique_resource(R, D) -> unique_resource<R, D>;

// TODO: Implement
struct scope_exit {
template <typename F>
scope_exit(F) {}
~scope_exit() {
// TODO: Cleanup
}
};

// TODO: Implement
struct scope_fail {
template <typename F>
scope_fail(F) {}
~scope_fail() {
// TODO: Cleanup
}
};

// TODO: Implement
struct scope_success {
template <typename F>
scope_success(F) {}
~scope_success() {
// TODO: Cleanup
}
};

} // namespace beman::scope

#endif // BEMAN_SCOPE_HPP
4 changes: 2 additions & 2 deletions src/beman/scope/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
add_library(beman.scope)
add_library(beman::scope ALIAS beman.scope)

target_sources(beman.scope PRIVATE identity.cpp)
target_sources(beman.scope PRIVATE scope.cpp)

target_sources(
beman.scope
PUBLIC
FILE_SET HEADERS
BASE_DIRS ${PROJECT_SOURCE_DIR}/include
FILES ${PROJECT_SOURCE_DIR}/include/beman/scope/identity.hpp
FILES ${PROJECT_SOURCE_DIR}/include/beman/scope/scope.hpp
)

set_target_properties(beman.scope PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON)
Expand Down
2 changes: 1 addition & 1 deletion src/beman/scope/identity.cpp → src/beman/scope/scope.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/scope/identity.hpp>
#include <beman/scope/scope.hpp>
8 changes: 6 additions & 2 deletions tests/beman/scope/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#add_executable(beman.scope.tests.identity)
#target_sources(beman.scope.tests.identity PRIVATE identity.test.cpp)
add_executable(beman.scope.tests.scope)
target_sources(beman.scope.tests.scope PRIVATE scope.test.cpp)

target_link_libraries(beman.scope.tests.scope PRIVATE beman::scope)

add_test(NAME beman.scope.tests.scope COMMAND beman.scope.tests.scope)
55 changes: 0 additions & 55 deletions tests/beman/scope/identity.test.cpp

This file was deleted.

5 changes: 5 additions & 0 deletions tests/beman/scope/scope.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

int main() {
// TODO: Add tests
}

0 comments on commit 37abed8

Please sign in to comment.