Skip to content

Commit 0343f5d

Browse files
authored
merge develop
2 parents 917ca76 + a8f6d0f commit 0343f5d

11 files changed

+1238
-504
lines changed

.github/workflows/code_testing.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
config:
15-
- os: ubuntu-22.04
16-
compiler: clang-16
1715
- os: ubuntu-22.04
1816
compiler: clang-17
1917
- os: ubuntu-22.04

.github/workflows/detect-pobr-diff.yml

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
conan-version: 2.3.1
1717
base-branch: ${{ github.base_ref }}
1818
search-path: >
19-
include/dice/template-library/polymorphic_allocator.hpp
2019
include/dice/template-library/flex_array.hpp
2120
include/dice/template-library/integral_template_tuple.hpp
2221
include/dice/template-library/integral_template_variant.hpp

.github/workflows/publish-conan-branch-package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
with:
1313
public_artifactory: true
1414
os: ubuntu-22.04
15-
compiler: clang-14
15+
compiler: clang-18
1616
cmake-version: 3.24.0
1717
conan-version: 2.3.1
1818
secrets:

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24)
22

33
project(
44
dice-template-library
5-
VERSION 1.8.1
5+
VERSION 1.9.0
66
DESCRIPTION
77
"This template library is a collection of template-oriented code that we, the Data Science Group at UPB, found pretty handy. It contains: `switch_cases` (Use runtime values in compile-time context), `integral_template_tuple` (Create a tuple-like structure that instantiates a template for a range of values), `integral_template_variant` (A wrapper type for `std::variant` guarantees to only contain variants of the form `T<IX>` and `for_{types,values,range}` (Compile time for loops for types, values or ranges))."
88
HOMEPAGE_URL "https://dice-research.org/")

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ It contains:
1515
- `tuple_algorithms`: Some algorithms for iterating tuples
1616
- `generator`: The reference implementation of `std::generator` from [P2502R2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2502r2.pdf)
1717
- `channel`: A single producer, single consumer queue
18+
- `variant2`: Like `std::variant` but optimized for exactly two types
1819

1920
## Usage
2021

@@ -87,6 +88,11 @@ all generator related things under namespace `std::`.
8788
A single producer, single consume queue. This can be used to communicate between threads in a more high level
8889
fashion than a mutex+container would allow.
8990

91+
### `variant2`
92+
Like `std::variant` but specifically optimized for usage with two types/variants.
93+
The internal representation is a `union` of the two types plus a 1 byte (3 state) discriminant.
94+
Additionally, `visit` does not involve any virtual function calls.
95+
9096
### Further Examples
9197

9298
Compilable code examples can be found in [examples](./examples). The example build requires the cmake
@@ -106,7 +112,7 @@ add
106112
FetchContent_Declare(
107113
dice-template-library
108114
GIT_REPOSITORY "https://github.com/dice-group/dice-template-library.git"
109-
GIT_TAG v1.8.1
115+
GIT_TAG v1.9.0
110116
GIT_SHALLOW TRUE)
111117
112118
FetchContent_MakeAvailable(dice-template-library)
@@ -125,7 +131,7 @@ target_link_libraries(your_target
125131
### conan
126132

127133
You can use it with [conan](https://conan.io/).
128-
To do so, you need to add `dice-template-library/1.8.1` to the `[requires]` section of your conan file.
134+
To do so, you need to add `dice-template-library/1.9.0` to the `[requires]` section of your conan file.
129135

130136
## Build and Run Tests and Examples
131137

examples/CMakeLists.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set(CMAKE_CXX_STANDARD 20)
2-
set(CMAKE_CXX_STANDARD_REQUIRED True)
2+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
33
set(CMAKE_CXX_EXTENSIONS OFF)
44

55
add_executable(examples_for examples_for.cpp)
@@ -72,3 +72,11 @@ target_link_libraries(example_channel
7272
PRIVATE
7373
dice-template-library::dice-template-library
7474
)
75+
76+
add_executable(example_variant2
77+
example_variant2.cpp)
78+
target_link_libraries(example_variant2
79+
PRIVATE
80+
dice-template-library::dice-template-library
81+
)
82+

examples/example_variant2.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <cassert>
2+
#include <string>
3+
4+
#include <dice/template-library/variant2.hpp>
5+
6+
namespace dtl = dice::template_library;
7+
using namespace std::literals;
8+
9+
int main() {
10+
// example adapted from from https://en.cppreference.com/w/cpp/utility/variant
11+
12+
dtl::variant2<int, float> v;
13+
dtl::variant2<int, float> w;
14+
15+
v = 42; // v contains int
16+
int i = dtl::get<int>(v);
17+
assert(42 == i); // succeeds
18+
w = dtl::get<int>(v);
19+
w = dtl::get<0>(v); // same effect as the previous line
20+
w = v; // same effect as the previous line
21+
22+
// dtl::get<double>(v); // error: no double in [int, float]
23+
// dtl::get<3>(v); // error: valid index values are 0 and 1
24+
25+
try {
26+
(void) dtl::get<float>(w); // w contains int, not float: will throw
27+
}
28+
catch (dtl::bad_variant_access const &ex) {
29+
assert(ex.what() == "bad variant access"s);
30+
}
31+
32+
dtl::variant<std::string> x("abc");
33+
// converting constructors work when unambiguous
34+
x = "def"; // converting assignment also works when unambiguous
35+
36+
dtl::variant<std::string, void const*> y("abc");
37+
// casts to void const* when passed a char const*
38+
assert(dtl::holds_alternative<void const*>(y)); // succeeds
39+
y = "xyz"s;
40+
assert(dtl::holds_alternative<std::string>(y)); // succeeds
41+
}

0 commit comments

Comments
 (0)