20class Tuple :
public ManagedObject<CassTuple> {
21 static constexpr auto kDELETER = [](CassTuple* ptr) { cass_tuple_free(ptr); };
24 Tuple(CassTuple* ptr);
26 template <
typename... Types>
27 explicit Tuple(std::tuple<Types...>&& value)
28 : ManagedObject{cass_tuple_new(std::tuple_size<std::tuple<Types...>>{}), kDELETER}
30 std::apply(std::bind_front(&Tuple::bind<Types...>,
this), std::move(value));
33 template <
typename... Args>
35 bind(Args&&... args)
const
38 (this->bindAt<Args>(idx++, std::forward<Args>(args)), ...);
41 template <
typename Type>
43 bindAt(std::size_t
const idx, Type&& value)
const
46 auto throwErrorIfNeeded = [idx](CassError rc, std::string_view label) {
48 auto const tag =
'[' + std::string{label} +
']';
49 throw std::logic_error(
50 tag +
" at idx " + to_string(idx) +
": " + cass_error_desc(rc)
55 using DecayedType = std::decay_t<Type>;
57 if constexpr (std::is_same_v<DecayedType, bool>) {
58 auto const rc = cass_tuple_set_bool(*
this, idx, value ? cass_true : cass_false);
59 throwErrorIfNeeded(rc,
"Bind bool");
62 else if constexpr (std::is_convertible_v<DecayedType, int64_t>) {
63 auto const rc = cass_tuple_set_int64(*
this, idx, std::forward<Type>(value));
64 throwErrorIfNeeded(rc,
"Bind int64");
65 }
else if constexpr (std::is_same_v<DecayedType, ripple::uint256>) {
66 auto const rc = cass_tuple_set_bytes(
69 static_cast<cass_byte_t const*
>(
static_cast<unsigned char const*
>(value.data())),
72 throwErrorIfNeeded(rc,
"Bind ripple::uint256");
80class TupleIterator :
public ManagedObject<CassIterator> {
82 TupleIterator(CassIterator* ptr);
84 [[nodiscard]]
static TupleIterator
85 fromTuple(CassValue
const* value);
87 template <
typename... Types>
88 [[nodiscard]] std::tuple<Types...>
91 return {extractNext<Types>()...};
95 template <
typename Type>
102 if (not cass_iterator_next(*
this))
103 throw std::logic_error(
"Could not extract next value from tuple iterator");
105 auto throwErrorIfNeeded = [](CassError rc, std::string_view label) {
107 auto const tag =
'[' + std::string{label} +
']';
108 throw std::logic_error(tag +
": " + cass_error_desc(rc));
112 using DecayedType = std::decay_t<Type>;
115 if constexpr (std::is_convertible_v<DecayedType, int64_t>) {
117 auto const rc = cass_value_get_int64(cass_iterator_get_value(*
this), &out);
118 throwErrorIfNeeded(rc,
"Extract int64 from tuple");
119 output =
static_cast<DecayedType
>(out);
static constexpr bool Unsupported
used for compile time checking of unsupported types
Definition UnsupportedType.hpp:7