Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
liss-h authored Aug 26, 2024
2 parents 917ca76 + a8f6d0f commit 0343f5d
Show file tree
Hide file tree
Showing 11 changed files with 1,238 additions and 504 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/code_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
fail-fast: false
matrix:
config:
- os: ubuntu-22.04
compiler: clang-16
- os: ubuntu-22.04
compiler: clang-17
- os: ubuntu-22.04
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/detect-pobr-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
conan-version: 2.3.1
base-branch: ${{ github.base_ref }}
search-path: >
include/dice/template-library/polymorphic_allocator.hpp
include/dice/template-library/flex_array.hpp
include/dice/template-library/integral_template_tuple.hpp
include/dice/template-library/integral_template_variant.hpp
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-conan-branch-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
with:
public_artifactory: true
os: ubuntu-22.04
compiler: clang-14
compiler: clang-18
cmake-version: 3.24.0
conan-version: 2.3.1
secrets:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24)

project(
dice-template-library
VERSION 1.8.1
VERSION 1.9.0
DESCRIPTION
"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))."
HOMEPAGE_URL "https://dice-research.org/")
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ It contains:
- `tuple_algorithms`: Some algorithms for iterating tuples
- `generator`: The reference implementation of `std::generator` from [P2502R2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2502r2.pdf)
- `channel`: A single producer, single consumer queue
- `variant2`: Like `std::variant` but optimized for exactly two types

## Usage

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

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

### Further Examples

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

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

## Build and Run Tests and Examples

Expand Down
10 changes: 9 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_executable(examples_for examples_for.cpp)
Expand Down Expand Up @@ -72,3 +72,11 @@ target_link_libraries(example_channel
PRIVATE
dice-template-library::dice-template-library
)

add_executable(example_variant2
example_variant2.cpp)
target_link_libraries(example_variant2
PRIVATE
dice-template-library::dice-template-library
)

41 changes: 41 additions & 0 deletions examples/example_variant2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <cassert>
#include <string>

#include <dice/template-library/variant2.hpp>

namespace dtl = dice::template_library;
using namespace std::literals;

int main() {
// example adapted from from https://en.cppreference.com/w/cpp/utility/variant

dtl::variant2<int, float> v;
dtl::variant2<int, float> w;

v = 42; // v contains int
int i = dtl::get<int>(v);
assert(42 == i); // succeeds
w = dtl::get<int>(v);
w = dtl::get<0>(v); // same effect as the previous line
w = v; // same effect as the previous line

// dtl::get<double>(v); // error: no double in [int, float]
// dtl::get<3>(v); // error: valid index values are 0 and 1

try {
(void) dtl::get<float>(w); // w contains int, not float: will throw
}
catch (dtl::bad_variant_access const &ex) {
assert(ex.what() == "bad variant access"s);
}

dtl::variant<std::string> x("abc");
// converting constructors work when unambiguous
x = "def"; // converting assignment also works when unambiguous

dtl::variant<std::string, void const*> y("abc");
// casts to void const* when passed a char const*
assert(dtl::holds_alternative<void const*>(y)); // succeeds
y = "xyz"s;
assert(dtl::holds_alternative<std::string>(y)); // succeeds
}
Loading

0 comments on commit 0343f5d

Please sign in to comment.