Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: CMake

on:
push:
branches: ["develop"]
pull_request:
branches: ["develop"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
schedule:
# run at 15:30 on day-of-month 7.
- cron: '30 15 7 * *'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: release
CTEST_OUTPUT_ON_FAILURE: 1

jobs:
build:
strategy:
fail-fast: false

matrix:
os: [windows, macos]
include:
- { os: macos, uname: appleclang }
# - { os: ubuntu, uname: gcc }
- { os: ubuntu, uname: llvm }
- { os: windows, uname: msvc }

# TODO(CK):
# type: [shared, static]
# include:
# - { type: shared, shared: YES }
# - { type: static, shared: NO }

runs-on: ${{ matrix.os }}-latest

steps:
- uses: actions/checkout@v4
- name: Setup build environment
uses: lukka/get-cmake@latest
with:
cmakeVersion: "~4.2.1"
ninjaVersion: "^1.13.0"

- name: Setup MSVC
if: startsWith(matrix.os, 'windows')
uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x64

- name: Setup Cpp
if: matrix.os != 'windows'
uses: aminya/setup-cpp@v1
with:
# compiler: ${{matrix.uname}}
compiler: llvm

- name: Configure CMake
run: cmake --preset ${{matrix.uname}}-${{env.BUILD_TYPE}} --log-level=VERBOSE

- name: Build
# Build your program with the given configuration
run: cmake --build --preset ${{matrix.uname}}-${{env.BUILD_TYPE}}

- name: Test
# Execute tests defined by the CMake configuration
run: ctest --preset ${{matrix.uname}}-${{env.BUILD_TYPE}}

# - name: Install
# # Install the project artefacts to CMAKE_INSTALL_PREFIX
# run: cmake --build --preset ${{matrix.uname}}-${{env.BUILD_TYPE}} --target install
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ project(

# gersemi: off

# Modules opt in only on compilers that support g++-15 and clang-20+
# Modules opt in only on compilers that support it: msvc, g++-15 and clang-20+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20)
set(CMAKE_CXX_SCAN_FOR_MODULES 1)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
set(CMAKE_CXX_SCAN_FOR_MODULES 1)
elseif(MSVC)
set(CMAKE_CXX_SCAN_FOR_MODULES 1)
else()
set(CMAKE_CXX_SCAN_FOR_MODULES 0)
endif()
Expand Down
4 changes: 4 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"_debug-base"
],
"cacheVariables": {
"CMAKE_CXX_STANDARD": "23",
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/appleclang-toolchain.cmake"
}
},
Expand All @@ -90,6 +91,7 @@
"_release-base"
],
"cacheVariables": {
"CMAKE_CXX_STANDARD": "23",
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/appleclang-toolchain.cmake"
}
},
Expand All @@ -101,6 +103,7 @@
"_debug-base"
],
"cacheVariables": {
"CMAKE_CXX_STANDARD": "23",
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/msvc-toolchain.cmake"
}
},
Expand All @@ -112,6 +115,7 @@
"_release-base"
],
"cacheVariables": {
"CMAKE_CXX_STANDARD": "23",
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/msvc-toolchain.cmake"
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ foreach(example ${ALL_EXAMPLES})
add_executable(${example})
target_sources(${example} PRIVATE ${example}.cpp)
target_link_libraries(${example} PRIVATE beman::scope)
add_test(NAME ${example} COMMAND ${example})
endforeach()
21 changes: 21 additions & 0 deletions gcovr.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = .
search-path = build

filter = examples/*
# filter = src/*
filter = include/*

exclude-directories = stagedir
exclude-directories = build/*/*/_deps
exclude-directories = tests
exclude-directories = conan

gcov-ignore-parse-errors = all
print-summary = yes

html-details = build/coverage/index.html

cobertura-pretty = yes
cobertura = build/cobertura.xml

#TBD delete-gcov-files = yes
54 changes: 39 additions & 15 deletions include/beman/scope/scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,38 @@

#include <concepts>
#include <exception>
#include <memory>
#include <type_traits>
#include <version>
#include <limits>

// clang-format off
#if __cplusplus < 202002L
#include <version>

#if defined(__cpp_concepts) && __cpp_concepts >= 201907L
// C++20 concepts supported
#elif __cplusplus < 202002L
#error "C++20 or later is required"
#endif
// clang-format on

#include <experimental/scope> //todo unconditional for unique_resource
// detect standard header first, then experimental, otherwise use local implementation
#if defined(__has_include)
# if __has_include(<scope>)
# include <scope>
# define BEMAN_SCOPE_USE_STD
# elif __has_include(<experimental/scope>)
# include <experimental/scope>
# define BEMAN_SCOPE_USE_STD_EXPERIMENTAL
# else
// no std scope header — fall through to local implementation below
# endif
#elif defined(__cpp_lib_scope) && __cpp_lib_scope >= 2023xxxxL
# include <scope>
# define BEMAN_SCOPE_USE_STD
#else
# warning "Missing feature __cpp_lib_scope"
#endif
// clang-format on

#ifdef BEMAN_SCOPE_USE_STD_EXPERIMENTAL

Expand All @@ -31,19 +52,19 @@ template <class EF>
using scope_success = std::experimental::scope_success<EF>;

// todo temporary
// template <class R, class D>
// using unique_resource = std::experimental::unique_resource<R, D>;
template <class R, class D>
using unique_resource = std::experimental::fundamentals_v3::unique_resource<R, D>;

// template <class R, class D, class S = std::decay_t<R>>
// unique_resource<std::decay_t<R>, std::decay_t<D>>
// make_unique_resource_checked(R&& r, const S& invalid, D&& d) noexcept(noexcept(
// std::experimental::make_unique_resource_checked(std::forward(r), std::forward(invalid), std::forward(d)))) {
// return std::experimental::make_unique_resource_checked(std::forward(r), std::forward(invalid), std::forward(d));
//}
template <class R, class D, class S = std::decay_t<R>>
unique_resource<std::decay_t<R>, std::decay_t<D>>
make_unique_resource_checked(R&& r, const S& invalid, D&& d) noexcept(noexcept(
std::experimental::make_unique_resource_checked(std::forward(r), std::forward(invalid), std::forward(d)))) {
return std::experimental::make_unique_resource_checked(std::forward(r), std::forward(invalid), std::forward(d));
}

} // namespace beman::scope

#else // ! BEMAN_SCOPE__USE_STD_EXPERIMENTAL
#elif defined(BEMAN_SCOPE_USE_STD)

namespace beman::scope {

Expand All @@ -52,8 +73,8 @@ template <class R, class D>
using unique_resource = std::experimental::unique_resource<R, D>;

// todo temporary
template <class R, class D, class S = std::decay_t<R> >
unique_resource<std::decay_t<R>, std::decay_t<D> >
template <class R, class D, class S = std::decay_t<R>>
unique_resource<std::decay_t<R>, std::decay_t<D>>
make_unique_resource_checked(R&& r, const S& invalid, D&& d) noexcept(noexcept(
std::experimental::make_unique_resource_checked(std::forward(r), std::forward(invalid), std::forward(d)))) {
return std::experimental::make_unique_resource_checked(std::forward(r), std::forward(invalid), std::forward(d));
Expand Down Expand Up @@ -421,6 +442,9 @@ using scope_fail = scope_guard<ExitFunc,

} // namespace beman::scope

#endif // BEMAN_SCOPE__USE_STD_EXPERIMENTAL
#else
#include "scope_impl.hpp"

#endif // BEMAN_SCOPE_USE_STD_EXPERIMENTAL

#endif // BEMAN_SCOPE_HPP
Loading