Skip to content

Commit e3163fe

Browse files
committed
Remove exception check from freestanding-deleted
1 parent ea30ea5 commit e3163fe

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ option(
2727
${PROJECT_IS_TOP_LEVEL}
2828
)
2929

30+
option(
31+
BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED
32+
"Enable freestanding mode. Default: OFF. Values: { ON, OFF }."
33+
OFF
34+
)
35+
36+
configure_file(
37+
"${PROJECT_SOURCE_DIR}/include/beman/inplace_vector/config.hpp.in"
38+
"${PROJECT_BINARY_DIR}/include/beman/inplace_vector/config.hpp"
39+
@ONLY
40+
)
41+
3042
include(FetchContent)
3143
include(GNUInstallDirs)
3244

@@ -38,7 +50,9 @@ target_include_directories(
3850
beman.inplace_vector
3951
INTERFACE
4052
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
53+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
4154
$<INSTALL_INTERFACE:include>
55+
$<INSTALL_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
4256
)
4357

4458
# Install the InplaceVector library to the appropriate destination
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// include/beman/inplace_vector/config.hpp.in -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef BEMAN_INPLACE_VECTOR_CONFIG_HPP
5+
#define BEMAN_INPLACE_VECTOR_CONFIG_HPP
6+
7+
#ifndef BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED
8+
#cmakedefine01 BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
9+
#endif
10+
11+
#endif

include/beman/inplace_vector/inplace_vector.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ prospectively choose to deem waived or otherwise exclude such Section(s) of
252252
the License, but only in their entirety and only with respect to the Combined
253253
Software.
254254
*/
255+
256+
#include <beman/inplace_vector/config.hpp>
257+
255258
#include <algorithm> // for rotate...
256259
#include <array>
257260
#include <concepts> // for lots...
@@ -271,8 +274,7 @@ Software.
271274
// Artifact from previous implementation, can be used as hints for optimizer
272275
#define IV_EXPECT(EXPR)
273276

274-
#if (!defined(__EXCEPTIONS) && !defined(_CPPUNWIND)) || \
275-
__STDC_HOSTED__ == 0 || BEMAN_IV_FREESTANDING_FORCE_TEST
277+
#if __STDC_HOSTED__ == 0 || BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED
276278
#define BEMAN_IV_FREESTANDING_DELETE(impl) = delete
277279
#else
278280
#define BEMAN_IV_FREESTANDING_DELETE(impl) impl

tests/beman/inplace_vector/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ add_gtest(size_n_data)
4242
add_gtest(erasure)
4343
add_gtest(freestanding)
4444

45-
set_source_files_properties(
46-
freestanding.test.cpp
47-
PROPERTIES COMPILE_FLAGS "-DBEMAN_IV_FREESTANDING_FORCE_TEST"
45+
target_compile_definitions(
46+
beman.inplace_vector.tests.freestanding
47+
PRIVATE BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED=1
4848
)
4949

5050
# constexpr test

tests/beman/inplace_vector/freestanding.test.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ TYPED_TEST(Freestanding, alltypes) {
1919
EXPECT_NE(vec.try_push_back(T{}), nullptr);
2020
}
2121
EXPECT_EQ(vec.try_push_back(T{}), nullptr);
22-
2322
EXPECT_EQ(vec.size(), IV::capacity());
24-
2523
vec.clear();
2624
EXPECT_EQ(vec.size(), 0);
25+
26+
static_assert(requires(IV vec, T t) { vec.try_push_back(t); });
27+
static_assert(requires(IV vec, T t) { vec.try_emplace_back(t); });
28+
29+
static_assert(!requires(IV vec, T t) { vec.push_back(t); });
30+
static_assert(!requires(IV vec, T t) { vec.emplace_back(t); });
31+
static_assert(!requires(IV vec, size_type t) { vec.reserve(t); });
32+
33+
// TODO make sure all of the freestanding-delete functions are deleted
2734
}
2835
} // namespace

0 commit comments

Comments
 (0)