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(tag +
" at idx " + to_string(idx) +
": " + cass_error_desc(rc));
72 using DecayedType = std::decay_t<Type>;
74 if constexpr (std::is_same_v<DecayedType, bool>) {
75 auto const rc = cass_tuple_set_bool(*
this, idx, value ? cass_true : cass_false);
76 throwErrorIfNeeded(rc,
"Bind bool");
79 else if constexpr (std::is_convertible_v<DecayedType, int64_t>) {
80 auto const rc = cass_tuple_set_int64(*
this, idx, std::forward<Type>(value));
81 throwErrorIfNeeded(rc,
"Bind int64");
82 }
else if constexpr (std::is_same_v<DecayedType, ripple::uint256>) {
83 auto const rc = cass_tuple_set_bytes(
86 static_cast<cass_byte_t const*
>(
static_cast<unsigned char const*
>(value.data())),
89 throwErrorIfNeeded(rc,
"Bind ripple::uint256");
102 fromTuple(CassValue
const* value);
104 template <
typename... Types>
105 [[nodiscard]] std::tuple<Types...>
108 return {extractNext<Types>()...};
112 template <
typename Type>
116 using std::to_string;
119 if (not cass_iterator_next(*
this))
120 throw std::logic_error(
"Could not extract next value from tuple iterator");
122 auto throwErrorIfNeeded = [](CassError rc, std::string_view label) {
124 auto const tag =
'[' + std::string{label} +
']';
125 throw std::logic_error(tag +
": " + cass_error_desc(rc));
129 using DecayedType = std::decay_t<Type>;
132 if constexpr (std::is_convertible_v<DecayedType, int64_t>) {
134 auto const rc = cass_value_get_int64(cass_iterator_get_value(*
this), &out);
135 throwErrorIfNeeded(rc,
"Extract int64 from tuple");
136 output =
static_cast<DecayedType
>(out);
static constexpr bool Unsupported
used for compile time checking of unsupported types
Definition UnsupportedType.hpp:26