Graphle 1.0.0
A C++20 header-only graph library
Loading...
Searching...
No Matches
storage_provider_helpers.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <common.hpp>
4
5#include <type_traits>
6#include <tuple>
7
8
9namespace graphle::store {
14 template <typename T, typename... Args> requires std::is_constructible_v<T, Args...>
16 public:
17 explicit provide_newly_constructed(Args&&... args) : args(GRAPHLE_FWD(args)...) {}
18
19 constexpr auto operator()(void) const & noexcept {
20 return std::apply([] (const auto&... args) { return T { args... }; }, args);
21 }
22
23 constexpr auto operator()(void) && noexcept {
24 return std::apply([] (auto&&... args) { return T { GRAPHLE_FWD(args)... }; }, std::move(args));
25 }
26 private:
27 std::tuple<Args...> args;
28 };
29
30
36 template <typename T, bool ReturnCleared = true> requires requires (T value) { value.clear(); }
38 public:
39 explicit provide_owned(T value, std::bool_constant<ReturnCleared> = {}) : value(std::move(value)) {}
40
41 constexpr auto operator()(void) const & noexcept {
42 if constexpr (ReturnCleared) value.clear();
43 return value;
44 }
45
46 constexpr auto operator()(void) && noexcept {
47 if constexpr (ReturnCleared) value.clear();
48 return std::move(value);
49 }
50 private:
51 T value;
52 };
53
54
61 template <typename T, bool ReturnCleared = true> requires requires (T value) { value.clear(); }
63 public:
64 explicit provide_external(T& value, std::bool_constant<ReturnCleared> = {}) : value(std::addressof(value)) {}
65
66 constexpr auto& operator()(void) const noexcept {
67 if constexpr (ReturnCleared) value->clear();
68 return *value;
69 }
70 private:
71 T* value;
72 };
73}
provide_external(T &value, std::bool_constant< ReturnCleared >={})
constexpr auto & operator()(void) const noexcept
constexpr auto operator()(void) const &noexcept
constexpr auto operator()(void) const &noexcept
constexpr auto operator()(void) &&noexcept
provide_owned(T value, std::bool_constant< ReturnCleared >={})
#define GRAPHLE_FWD(...)
Definition: common.hpp:14