39class Tuple :
public ManagedObject<CassTuple> {
40 static constexpr auto kDELETER = [](CassTuple* ptr) { cass_tuple_free(ptr); };
43 Tuple(CassTuple* ptr);
45 template <
typename... Types>
46 explicit Tuple(std::tuple<Types...>&& value)
47 : ManagedObject{cass_tuple_new(std::tuple_size<std::tuple<Types...>>{}), kDELETER}
49 std::apply(std::bind_front(&Tuple::bind<Types...>,
this), std::move(value));
52 template <
typename... Args>
54 bind(Args&&... args)
const
57 (this->bindAt<Args>(idx++, std::forward<Args>(args)), ...);
60 template <
typename Type>
62 bindAt(std::size_t
const idx, Type&& value)
const
65 auto throwErrorIfNeeded = [idx](CassError rc, std::string_view label) {
67 auto const tag =
'[' + std::string{label} +
']';
68 throw std::logic_error(
69 tag +
" at idx " + to_string(idx) +
": " + cass_error_desc(rc)
74 using DecayedType = std::decay_t<Type>;
76 if constexpr (std::is_same_v<DecayedType, bool>) {
77 auto const rc = cass_tuple_set_bool(*
this, idx, value ? cass_true : cass_false);
78 throwErrorIfNeeded(rc,
"Bind bool");
81 else if constexpr (std::is_convertible_v<DecayedType, int64_t>) {
82 auto const rc = cass_tuple_set_int64(*
this, idx, std::forward<Type>(value));
83 throwErrorIfNeeded(rc,
"Bind int64");
84 }
else if constexpr (std::is_same_v<DecayedType, ripple::uint256>) {
85 auto const rc = cass_tuple_set_bytes(
88 static_cast<cass_byte_t const*
>(
static_cast<unsigned char const*
>(value.data())),
91 throwErrorIfNeeded(rc,
"Bind ripple::uint256");
99class TupleIterator :
public ManagedObject<CassIterator> {
101 TupleIterator(CassIterator* ptr);
103 [[nodiscard]]
static TupleIterator
104 fromTuple(CassValue
const* value);
106 template <
typename... Types>
107 [[nodiscard]] std::tuple<Types...>
110 return {extractNext<Types>()...};
114 template <
typename Type>
118 using std::to_string;
121 if (not cass_iterator_next(*
this))
122 throw std::logic_error(
"Could not extract next value from tuple iterator");
124 auto throwErrorIfNeeded = [](CassError rc, std::string_view label) {
126 auto const tag =
'[' + std::string{label} +
']';
127 throw std::logic_error(tag +
": " + cass_error_desc(rc));
131 using DecayedType = std::decay_t<Type>;
134 if constexpr (std::is_convertible_v<DecayedType, int64_t>) {
136 auto const rc = cass_value_get_int64(cass_iterator_get_value(*
this), &out);
137 throwErrorIfNeeded(rc,
"Extract int64 from tuple");
138 output =
static_cast<DecayedType
>(out);
static constexpr bool Unsupported
used for compile time checking of unsupported types
Definition UnsupportedType.hpp:26