Skip to content

Commit

Permalink
Use concepts for requirements (#475)
Browse files Browse the repository at this point in the history
Remove C++14 and C++17 support.

Update README for acceptance and conceptification
  • Loading branch information
jbcoe authored Nov 30, 2024
1 parent 5254501 commit c7b4c0a
Show file tree
Hide file tree
Showing 14 changed files with 498 additions and 1,652 deletions.
87 changes: 0 additions & 87 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,51 +43,6 @@ cc_test(
],
)

cc_library(
name = "indirect_cxx14",
hdrs = [
"indirect.h",
"indirect_cxx14.h",
],
copts = ["-Iexternal/value_types/"],
defines = ["XYZ_INDIRECT_CXX_14"],
visibility = ["//visibility:public"],
)

cc_test(
name = "indirect_cxx14_test",
size = "small",
srcs = [
"indirect_test.cc",
],
copts = ["-std=c++14"],
deps = [
"feature_check",
"indirect_cxx14",
"tagged_allocator",
"test_helpers",
"tracking_allocator",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "indirect_cxx17_test",
size = "small",
srcs = [
"indirect_test.cc",
],
copts = ["-std=c++17"],
deps = [
"feature_check",
"indirect_cxx14",
"tagged_allocator",
"test_helpers",
"tracking_allocator",
"@com_google_googletest//:gtest_main",
],
)

cc_library(
name = "polymorphic",
hdrs = ["polymorphic.h"],
Expand All @@ -110,45 +65,3 @@ cc_test(
"@com_google_googletest//:gtest_main",
],
)

cc_library(
name = "polymorphic_cxx14",
hdrs = ["polymorphic_cxx14.h"],
copts = ["-Iexternal/value_types/"],
defines = ["XYZ_POLYMORPHIC_CXX_14"],
visibility = ["//visibility:public"],
)

cc_test(
name = "polymorphic_cxx14_test",
size = "small",
srcs = [
"polymorphic_test.cc",
],
copts = ["-std=c++14"],
deps = [
"feature_check",
"polymorphic_cxx14",
"tagged_allocator",
"test_helpers",
"tracking_allocator",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "polymorphic_cxx17_test",
size = "small",
srcs = [
"polymorphic_test.cc",
],
copts = ["-std=c++17"],
deps = [
"feature_check",
"polymorphic_cxx14",
"tagged_allocator",
"test_helpers",
"tracking_allocator",
"@com_google_googletest//:gtest_main",
],
)
77 changes: 0 additions & 77 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,6 @@ target_sources(indirect
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/indirect.h>
)

xyz_add_library(
NAME indirect_cxx14
ALIAS xyz_value_types::indirect_cxx14
DEFINITIONS XYZ_INDIRECT_CXX_14
VERSION 14
)
target_sources(indirect_cxx14
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/indirect_cxx14.h>
)

xyz_add_library(
NAME indirect_cxx17
ALIAS xyz_value_types::indirect_cxx17
DEFINITIONS XYZ_INDIRECT_CXX_14
VERSION 17
)
target_sources(indirect_cxx17
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/indirect_cxx14.h>
)

xyz_add_library(
NAME polymorphic
ALIAS xyz_value_types::polymorphic
Expand All @@ -77,38 +55,11 @@ target_sources(polymorphic
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/polymorphic.h>
)

xyz_add_library(
NAME polymorphic_cxx14
ALIAS xyz_value_types::polymorphic_cxx14
DEFINITIONS XYZ_POLYMORPHIC_CXX_14
VERSION 14
)
target_sources(polymorphic_cxx14
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/polymorphic_cxx14.h>
)

xyz_add_library(
NAME polymorphic_cxx17
ALIAS xyz_value_types::polymorphic_cxx17
DEFINITIONS XYZ_POLYMORPHIC_CXX_14
VERSION 17
)
target_sources(polymorphic_cxx17
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/polymorphic_cxx14.h>
)

if (${XYZ_VALUE_TYPES_IS_NOT_SUBPROJECT})

add_subdirectory(benchmarks)
add_subdirectory(compile_checks)

if(!MSVC)
# There are issues with constexpr/consteval in MSVC 2019 and MSVC 2022.
add_subdirectory(compile_checks)
endif(!MSVC)

if (${BUILD_TESTING})
FetchContent_Declare(
googletest
Expand Down Expand Up @@ -150,40 +101,12 @@ if (${XYZ_VALUE_TYPES_IS_NOT_SUBPROJECT})
FILES indirect_test.cc
)

xyz_add_test(
NAME indirect_cxx14_test
LINK_LIBRARIES indirect_cxx14
FILES indirect_test.cc
VERSION 14
)

xyz_add_test(
NAME indirect_cxx17_test
LINK_LIBRARIES indirect_cxx17
FILES indirect_test.cc
VERSION 17
)

xyz_add_test(
NAME polymorphic_test
LINK_LIBRARIES polymorphic
FILES polymorphic_test.cc
)

xyz_add_test(
NAME polymorphic_cxx14_test
LINK_LIBRARIES polymorphic_cxx14
FILES polymorphic_test.cc
VERSION 14
)

xyz_add_test(
NAME polymorphic_cxx17_test
LINK_LIBRARIES polymorphic_cxx17
FILES polymorphic_test.cc
VERSION 17
)

if (ENABLE_CODE_COVERAGE)
coverage_evaluate()
endif()
Expand Down
36 changes: 8 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,17 @@ of writing and maintaining error-prone boilerplate code.

## Standardization

We'd like to see `indirect` and `polymorphic` included in a future version of
the C++ standard. Prior work on standardizing similar types, `indirect_value`
and `polymorphic_value` can be found at
`indirect` and `polymorphic` have been accepted into the C++ draft standard for
2026 as part of [`indirect` and `polymorphic`: Vocabulary Types for Composite
Class Design](https://isocpp.org/files/papers/P3019R11.pdf)

* [A polymorphic value-type for
C++](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0201r5.html)

* [indirect_value: A Free-Store-Allocated Value Type For
C++](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1950r2.html)

Design of these two types is so deeply coupled that future work will proceed in
[an updated paper](DRAFT.md).
The reference implementation in this repository differs slightly from the
proposal: we use concepts for requirements to support incomplete types in
variants. We will submit a library issue to the C++ standard committee to amend
the proposal.

## Use

The `indirect` and `polymorphic` class templates are header-only. To use them,
include the headers `indirect.h` and `polymorphic.h` in your project.

Expand Down Expand Up @@ -90,23 +87,6 @@ by adding the includes:
#include <https://raw.githubusercontent.com/jbcoe/value_types/main/polymorphic.h>
```

### Compatibility

We have C++14 implementations of `indirect` and `polymorphic` available as
`indirect_cxx14.h` and `polymorphic_cxx14.h`.

C++14 implementations can be tried out in compiler explorer by using the includes:

```cpp
#include <https://raw.githubusercontent.com/jbcoe/value_types/main/indirect_cxx14.h>
#include <https://raw.githubusercontent.com/jbcoe/value_types/main/polymorphic_cxx14.h>
```

or by including headers `indirect_cxx14.h` and `polymorphic_cxx14.h` into your project.

We duplicate some code between the C++20 and C++14 implementations so that
single-file includes work.

## License

This code is licensed under the MIT License. See [LICENSE](LICENSE) for details.
Expand Down
26 changes: 26 additions & 0 deletions compile_checks/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc_library(
visibility = ["//visibility:private"],
deps = ["//:indirect"],
)

build_test(
name = "indirect_in_variant_build_test",
targets = ["indirect_in_variant"],
Expand All @@ -17,6 +18,7 @@ cc_library(
visibility = ["//visibility:private"],
deps = ["//:indirect"],
)

build_test(
name = "indirect_as_member_build_test",
targets = ["indirect_as_member"],
Expand Down Expand Up @@ -77,3 +79,27 @@ build_test(
name = "polymorphic_pimpl_build_test",
targets = ["polymorphic_pimpl"],
)

cc_library(
name = "polymorphic_in_variant",
srcs = ["polymorphic_in_variant.cc"],
visibility = ["//visibility:private"],
deps = ["//:polymorphic"],
)

build_test(
name = "polymorphic_in_variant_build_test",
targets = ["polymorphic_in_variant"],
)

cc_library(
name = "polymorphic_as_member",
srcs = ["polymorphic_as_member.cc"],
visibility = ["//visibility:private"],
deps = ["//:polymorphic"],
)

build_test(
name = "polymorphic_as_member_build_test",
targets = ["polymorphic_as_member"],
)
66 changes: 42 additions & 24 deletions compile_checks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ target_link_libraries(indirect_pimpl
common_compiler_settings
)

if(NOT MSVC)
add_library(polymorphic_consteval OBJECT)
target_sources(polymorphic_consteval
PRIVATE
polymorphic_consteval.cc
)
target_link_libraries(polymorphic_consteval
PRIVATE
polymorphic
common_compiler_settings
)
endif()
add_library(polymorphic_consteval OBJECT)
target_sources(polymorphic_consteval
PRIVATE
polymorphic_consteval.cc
)
target_link_libraries(polymorphic_consteval
PRIVATE
polymorphic
common_compiler_settings
)

add_library(polymorphic_pimpl OBJECT)
target_sources(polymorphic_pimpl
Expand All @@ -59,15 +57,35 @@ target_link_libraries(indirect_as_member
common_compiler_settings
)

if(NOT MSVC)
add_library(indirect_in_variant OBJECT)
target_sources(indirect_in_variant
PRIVATE
indirect_in_variant.cc
)
target_link_libraries(indirect_in_variant
PRIVATE
indirect
common_compiler_settings
)
endif()
add_library(indirect_in_variant OBJECT)
target_sources(indirect_in_variant
PRIVATE
indirect_in_variant.cc
)
target_link_libraries(indirect_in_variant
PRIVATE
indirect
common_compiler_settings
)

add_library(polymorphic_as_member OBJECT)
target_sources(polymorphic_as_member
PRIVATE
polymorphic_as_member.cc
)
target_link_libraries(polymorphic_as_member
PRIVATE
polymorphic
common_compiler_settings
)

add_library(polymorphic_in_variant OBJECT)
target_sources(polymorphic_in_variant
PRIVATE
polymorphic_in_variant.cc
)
target_link_libraries(polymorphic_in_variant
PRIVATE
polymorphic
common_compiler_settings
)
Loading

0 comments on commit c7b4c0a

Please sign in to comment.