Skip to content

Commit 1c2de9b

Browse files
committed
ci updates
use std::out_ptr if available allow put std::string_view into database
1 parent b770f95 commit 1c2de9b

3 files changed

Lines changed: 35 additions & 18 deletions

File tree

.github/workflows/linux.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ jobs:
1616
cxx: 20
1717
- compiler: llvm
1818
compiler-version: 18
19-
cxx: 20
19+
cxx: 20
20+
- compiler: llvm
21+
compiler-version: 19
22+
cxx: 23
2023
- compiler: gcc
2124
compiler-version: 11
22-
additional-dep: "g++-11"
2325
cxx: 20
2426
- compiler: gcc
2527
compiler-version: 12
@@ -29,9 +31,9 @@ jobs:
2931
cxx: 20
3032
- compiler: gcc
3133
compiler-version: 14
32-
cxx: 20
34+
cxx: 23
3335
name: "${{ github.job }} (C++${{ matrix.cxx }}-${{ matrix.compiler }}-${{ matrix.compiler-version }})"
34-
runs-on: ubuntu-24.04
36+
runs-on: ubuntu-25.04
3537
steps:
3638
- name: Checkout
3739
uses: actions/checkout@v4
@@ -52,7 +54,12 @@ jobs:
5254
- name: Install dependencies
5355
run: |
5456
sudo apt update
55-
sudo apt install -y ninja-build ${{ matrix.additional-dep }}
57+
sudo apt install -y ninja-build ${{ matrix.deps }}
58+
if [[ "${{ matrix.compiler }}" == "llvm" ]]; then
59+
sudo apt install "clang++-${{ matrix.compiler }}"
60+
elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then
61+
sudo apt install "g++-${{ matrix.compiler }}"
62+
fi
5663
- name: Compile
5764
run: |
5865
if [[ "${{ matrix.compiler }}" == "llvm" ]]; then

include/oryx/key_value_database.hpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
namespace oryx {
1515
namespace detail {
1616

17+
template <typename T, typename... Us>
18+
struct is_same_r : std::bool_constant<(std::is_same_v<T, Us> || ...)> {};
19+
20+
template <typename T, typename... Us>
21+
inline constexpr bool is_same_r_v = is_same_r<T, Us...>::value;
22+
1723
template <typename T>
1824
constexpr auto FromChars(std::string_view s) -> std::optional<T> {
1925
T val;
@@ -33,18 +39,18 @@ constexpr auto FromChars<bool>(std::string_view s) -> std::optional<bool> {
3339
}
3440

3541
template <typename T>
36-
auto Read(const std::string& val) -> std::optional<T> {
42+
constexpr auto Read(const std::string& val) -> std::optional<T> {
3743
using _T = std::remove_cvref_t<T>;
3844

39-
if constexpr (std::is_same<_T, std::string>()) {
45+
if constexpr (std::is_same_v<_T, std::string>)
4046
return val;
41-
} else if constexpr (std::is_same<_T, bool>()) {
47+
else if constexpr (std::is_same_v<_T, bool>)
4248
return FromChars<bool>(val);
43-
} else if constexpr (std::is_floating_point<_T>()) {
49+
else if constexpr (std::is_floating_point_v<_T>)
4450
return FromChars<T>(val);
45-
} else if constexpr (std::is_integral<_T>()) {
51+
else if constexpr (std::is_integral_v<_T>)
4652
return FromChars<T>(val);
47-
} else {
53+
else {
4854
if (auto result = rfl::json::read<T>(val); result) {
4955
return result.value();
5056
} else {
@@ -54,20 +60,19 @@ auto Read(const std::string& val) -> std::optional<T> {
5460
}
5561

5662
template <typename T>
57-
auto Write(const T& obj) -> std::string {
63+
constexpr auto Write(const T& obj) {
5864
using _T = std::remove_cvref_t<T>;
5965

60-
if constexpr (std::is_same<_T, std::string>()) {
66+
if constexpr (is_same_r_v<_T, std::string, std::string_view>)
6167
return obj;
62-
} else if constexpr (std::is_same<_T, bool>()) {
68+
else if constexpr (std::is_same_v<_T, bool>)
6369
return std::to_string(static_cast<uint8_t>(obj));
64-
} else if constexpr (std::is_floating_point<_T>()) {
70+
else if constexpr (std::is_floating_point_v<_T>)
6571
return std::to_string(obj);
66-
} else if constexpr (std::is_integral<_T>()) {
72+
else if constexpr (std::is_integral_v<_T>)
6773
return std::to_string(obj);
68-
} else {
74+
else
6975
return rfl::json::write(obj);
70-
}
7176
}
7277

7378
} // namespace detail
@@ -79,11 +84,15 @@ class KeyValueDatabase {
7984
auto Open(const std::string& name, const leveldb::Options& opts = DefaultOptions()) -> leveldb::Status {
8085
Close();
8186

87+
#ifdef __cpp_lib_out_ptr
88+
const auto status = leveldb::DB::Open(opts, name, std::out_ptr(handle_));
89+
#else
8290
leveldb::DB* db;
8391
const auto status = leveldb::DB::Open(opts, name, &db);
8492
if (status.ok()) {
8593
handle_ = std::unique_ptr<leveldb::DB>(db);
8694
}
95+
#endif
8796
return status;
8897
}
8998

tests/read_write.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ TEST_CASE("Reading supported types") {
6262

6363
TEST_CASE("Writing supported types") {
6464
CHECK_EQ(detail::Write<std::string>("hello world1232!*2`-."), "hello world1232!*2`-.");
65+
CHECK_EQ(detail::Write<std::string_view>("hello world1232!*2`-."), "hello world1232!*2`-.");
6566
CHECK_EQ(detail::Write<bool>(false), "0");
6667
CHECK_EQ(detail::Write<bool>(true), "1");
6768
CHECK_EQ(detail::Write<double>(1.256), "1.256000"); // std::to_string appends 0 at the end for some reason

0 commit comments

Comments
 (0)