Skip to content

Commit 870e2e1

Browse files
authored
merge develop
2 parents c20a94f + 070a706 commit 870e2e1

File tree

11 files changed

+501
-5
lines changed

11 files changed

+501
-5
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Detect POBR diff
2+
3+
on: [ pull_request ]
4+
5+
concurrency:
6+
group: detect-pobr-diff-${{ github.workflow }}-${{ github.ref }}
7+
cancel-in-progress: true
8+
9+
jobs:
10+
detect-pobr-diff:
11+
uses: dice-group/cpp-conan-release-reusable-workflow/.github/workflows/abi-diff.yml@main
12+
with:
13+
os: ubuntu-22.04
14+
compiler: clang-16
15+
cmake-version: 3.24.0
16+
conan-version: 2.3.1
17+
base-branch: ${{ github.base_ref }}
18+
search-path: >
19+
include/dice/template-library/polymorphic_allocator.hpp
20+
include/dice/template-library/flex_array.hpp
21+
include/dice/template-library/integral_template_tuple.hpp
22+
include/dice/template-library/integral_template_variant.hpp
23+
abi-version-header: include/dice/template-library/version.hpp
24+
abi-version-const: dice::template_library::pobr_version
25+
secrets:
26+
CONAN_USER: ""
27+
CONAN_PW: ""

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,4 @@ test_package/build/
107107
test_package/CMakeUserPresets.json
108108
/CMakeUserPresets.json
109109
/conan_provider.cmake
110+
include/dice/template-library/version.hpp

CMakeLists.txt

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

33
project(
44
dice-template-library
5-
VERSION 1.6.0
5+
VERSION 1.7.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/")
9+
set(POBR_VERSION 1) # Persisted Object Binary Representation
10+
11+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/dice/template-library/version.hpp)
912

1013
option(BUILD_TESTING "build tests" OFF)
1114
option(BUILD_EXAMPLES "build examples" OFF)
1215

1316
if (PROJECT_IS_TOP_LEVEL)
1417
set(CONAN_INSTALL_ARGS "${CONAN_INSTALL_ARGS};-o=boost/*:header_only=True")
18+
19+
if (BUILD_TESTING)
20+
set(CONAN_INSTALL_ARGS "${CONAN_INSTALL_ARGS};-o=&:with_test_deps=True")
21+
endif ()
1522
endif ()
1623

1724
# conan requires cmake build type to be specified and it is generally a good idea

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ It contains:
1414
- `flex_array`: A combination of `std::array` and `std::span`
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)
17+
- `channel`: A single producer, single consumer queue
1718

1819
## Usage
1920

@@ -82,6 +83,10 @@ If you want this generator to serve as a drop in replacement for `std::generator
8283
use `#define DICE_TEMPLATELIBRARY_GENERATOR_STD_COMPAT 1` before including the generator header. That will export
8384
all generator related things under namespace `std::`.
8485

86+
### `channel`
87+
A single producer, single consume queue. This can be used to communicate between threads in a more high level
88+
fashion than a mutex+container would allow.
89+
8590
### Further Examples
8691

8792
Compilable code examples can be found in [examples](./examples). The example build requires the cmake
@@ -101,7 +106,7 @@ add
101106
FetchContent_Declare(
102107
dice-template-library
103108
GIT_REPOSITORY "https://github.com/dice-group/dice-template-library.git"
104-
GIT_TAG v1.6.0
109+
GIT_TAG v1.7.0
105110
GIT_SHALLOW TRUE)
106111
107112
FetchContent_MakeAvailable(dice-template-library)
@@ -120,7 +125,7 @@ target_link_libraries(your_target
120125
### conan
121126

122127
You can use it with [conan](https://conan.io/).
123-
To do so, you need to add `dice-template-library/1.6.0` to the `[requires]` section of your conan file.
128+
To do so, you need to add `dice-template-library/1.7.0` to the `[requires]` section of your conan file.
124129

125130
## Build and Run Tests and Examples
126131

cmake/version.hpp.in

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef DICE_TEMPLATELIBRARY_VERSION_HPP
2+
#define DICE_TEMPLATELIBRARY_VERSION_HPP
3+
4+
#include <array>
5+
6+
namespace dice::template_library {
7+
inline constexpr char name[] = "@PROJECT_NAME@";
8+
inline constexpr char version[] = "@PROJECT_VERSION@";
9+
inline constexpr std::array<int, 3> version_tuple = {@PROJECT_VERSION_MAJOR@, @PROJECT_VERSION_MINOR@, @PROJECT_VERSION_PATCH@};
10+
inline constexpr int pobr_version = @POBR_VERSION@; ///< persisted object binary representation version
11+
} // namespace dice::template_library
12+
13+
#endif // DICE_TEMPLATELIBRARY_VERSION_HPP

conanfile.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@ class DiceTemplateLibrary(ConanFile):
1818
settings = "os", "compiler", "build_type", "arch"
1919
exports_sources = "include/*", "CMakeLists.txt", "cmake/*", "LICENSE"
2020
no_copy_source = True
21+
options = {
22+
"with_test_deps": [True, False],
23+
}
24+
default_options = {
25+
"with_test_deps": False,
26+
}
2127

2228
def requirements(self):
23-
self.test_requires("boost/1.83.0")
24-
self.test_requires("doctest/2.4.11")
29+
if self.options.with_test_deps:
30+
self.test_requires("boost/1.83.0")
31+
self.test_requires("doctest/2.4.11")
2532

2633
def layout(self):
2734
cmake_layout(self)

examples/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,10 @@ target_link_libraries(example_generator
6565
PRIVATE
6666
dice-template-library::dice-template-library
6767
)
68+
69+
add_executable(example_channel
70+
example_channel.cpp)
71+
target_link_libraries(example_channel
72+
PRIVATE
73+
dice-template-library::dice-template-library
74+
)

examples/example_channel.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <dice/template-library/channel.hpp>
2+
3+
#include <algorithm>
4+
#include <iostream>
5+
#include <thread>
6+
#include <vector>
7+
8+
9+
int main() {
10+
dice::template_library::channel<int> chan{8};
11+
12+
std::jthread thrd{[&chan]() {
13+
std::vector<int> ints;
14+
for (int x : chan) {
15+
ints.push_back(x);
16+
std::cout << x << ' ';
17+
}
18+
19+
assert(std::ranges::equal(ints, std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
20+
}};
21+
22+
for (int x = 0; x < 10; ++x) {
23+
chan.push(x);
24+
}
25+
chan.close(); // don't forget to close
26+
}

0 commit comments

Comments
 (0)