24#ifndef MYSQL_CONTAINERS_BASIC_CONTAINER_WRAPPER_H
25#define MYSQL_CONTAINERS_BASIC_CONTAINER_WRAPPER_H
56template <
class Self_tp,
class Wrapped_tp,
57 mysql::utils::Shall_catch shall_catch = mysql::utils::Shall_catch::no>
68 template <
class... Args_t>
71 noexcept(
Wrapped_t(std::forward<Args_t>(args)...)))
72 :
m_wrapped(std::forward<Args_t>(args)...) {}
78 template <std::input_iterator First_iterator_t,
79 std::sentinel_for<First_iterator_t> Sentinel_t>
80 requires requires(
Wrapped_t w, First_iterator_t f, Sentinel_t s) {
83 [[nodiscard]]
auto assign(
const First_iterator_t &first,
84 const Sentinel_t &last)
86 noexcept(shall_catch == mysql::utils::Shall_catch::yes ||
87 noexcept(std::declval<Wrapped_t>().assign(first, last))) {
97 template <
class Other_t>
98 [[nodiscard]]
auto assign(
const Other_t &other)
noexcept(
99 shall_catch == mysql::utils::Shall_catch::yes ||
100 noexcept(std::declval<Self_t>().assign(other.begin(), other.end()))) {
103 if constexpr (std::same_as<
decltype(
self().
assign(other.begin(),
111 return self().
assign(other.begin(), other.end());
119 requires std::is_nothrow_move_assignable_v<Wrapped_t>
121 if (&other == &
self())
return;
138 constexpr bool has_memory_resource =
139 requires {
m_wrapped.get_memory_resource(); };
140 constexpr bool has_allocator =
141 requires {
m_wrapped.get_allocator().get_memory_resource(); };
142 if constexpr (has_memory_resource) {
144 }
else if constexpr (has_allocator) {
145 return m_wrapped.get_allocator().get_memory_resource();
148 has_memory_resource || has_allocator,
149 "Wrapped class has neither a get_allocator() member function that "
150 "returns an object having a get_memory_resource() function, nor a "
151 "get_memory_resource() member function of its own.");
193 [[nodiscard]]
auto &
self()
noexcept {
return static_cast<Self_t &
>(*this); }
196 [[nodiscard]]
const auto &
self()
const noexcept {
197 return static_cast<const Self_t &
>(*this);
#define DEDUCED_NOEXCEPT_FUNCTION(X)
Helper macro to define a function that returns the result of a single expression, and has a condition...
Definition: call_and_catch.h:151
CRTP base class (mixin) to define a wrapper around a container.
Definition: basic_container_wrapper.h:59
auto begin() noexcept
Definition: basic_container_wrapper.h:164
Wrapped_t m_wrapped
Wrapped object.
Definition: basic_container_wrapper.h:201
Wrapped_tp Wrapped_t
Definition: basic_container_wrapper.h:64
void clear() noexcept
Clear the wrapped object.
Definition: basic_container_wrapper.h:128
const auto & wrapped() const &noexcept
Definition: basic_container_wrapper.h:186
auto get_memory_resource() const noexcept
Return the memory resource used by the wrapped object.
Definition: basic_container_wrapper.h:137
auto assign(const First_iterator_t &first, const Sentinel_t &last) noexcept(shall_catch==mysql::utils::Shall_catch::yes||noexcept(std::declval< Wrapped_t >().assign(first, last)))
Assign a range defined by the two iterators to the wrapped object.
Definition: basic_container_wrapper.h:83
auto begin() const noexcept
Definition: basic_container_wrapper.h:170
auto empty() const noexcept
Definition: basic_container_wrapper.h:176
auto end() noexcept
Definition: basic_container_wrapper.h:167
Self_tp Self_t
Definition: basic_container_wrapper.h:60
void assign(Self_t &&other) noexcept
Move-assign the other object to the wrapped object.
Definition: basic_container_wrapper.h:118
auto & wrapped() &noexcept
Definition: basic_container_wrapper.h:183
auto end() const noexcept
Definition: basic_container_wrapper.h:173
auto size() const noexcept
Definition: basic_container_wrapper.h:179
auto && wrapped() &&noexcept
Definition: basic_container_wrapper.h:189
auto get_allocator() const noexcept
Return the allocator used by the wrapped object.
Definition: basic_container_wrapper.h:159
auto assign(const Other_t &other) noexcept(shall_catch==mysql::utils::Shall_catch::yes||noexcept(std::declval< Self_t >().assign(other.begin(), other.end())))
Copy-assign the other object to the wrapped object.
Definition: basic_container_wrapper.h:98
Basic_container_wrapper(Args_t &&...args) noexcept(noexcept(Wrapped_t(std::forward< Args_t >(args)...)))
Constructor that delegates all parameters to the constructor of the wrapped class.
Definition: basic_container_wrapper.h:70
Basic_container_wrapper< Self_t, Wrapped_tp, shall_catch > This_t
Definition: basic_container_wrapper.h:61
CRTP base class to provide members of a collection based on an implementation that provides begin/end...
Definition: collection_interface.h:90
Definition: basic_container_wrapper.h:42
decltype(auto) conditional_call_and_catch(const Function_t &function, Args_t &&...args) noexcept(noexcept(function(std::forward< Args_t >(args)...))||shall_catch==Shall_catch::yes)
Call function, and if shall_catch is true, catch exceptions and wrap them in the return value.
Definition: call_and_catch.h:112
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
bool is_same_object(const Obj1_t &obj1, const Obj2_t &obj2)
Return true if the types of the two objects are either equal or one derived from the other,...
Definition: is_same_object.h:40