cql3: expr: expression: make the argument of to_range a forwarding reference

Make to_range able to handle rvalues. We will pass managed_bytes&& to it
in the next patch to avoid pointless copying.
The public declaration of to_range is changed to a concrete function to avoid
having to explicitly instantiate to_range for all possible reference types of
clustering_key_prefix.
This commit is contained in:
Michał Chojnowski
2021-03-25 09:44:51 +01:00
parent 0bb959e890
commit 6e7e795dfd
2 changed files with 11 additions and 9 deletions

View File

@@ -673,25 +673,28 @@ std::vector<managed_bytes_opt> first_multicolumn_bound(
}
template<typename T>
nonwrapping_range<T> to_range(oper_t op, const T& val) {
nonwrapping_range<std::remove_cvref_t<T>> to_range(oper_t op, T&& val) {
using U = std::remove_cvref_t<T>;
static constexpr bool inclusive = true, exclusive = false;
switch (op) {
case oper_t::EQ:
return nonwrapping_range<T>::make_singular(val);
return nonwrapping_range<U>::make_singular(std::forward<T>(val));
case oper_t::GT:
return nonwrapping_range<T>::make_starting_with(interval_bound(val, exclusive));
return nonwrapping_range<U>::make_starting_with(interval_bound(std::forward<T>(val), exclusive));
case oper_t::GTE:
return nonwrapping_range<T>::make_starting_with(interval_bound(val, inclusive));
return nonwrapping_range<U>::make_starting_with(interval_bound(std::forward<T>(val), inclusive));
case oper_t::LT:
return nonwrapping_range<T>::make_ending_with(interval_bound(val, exclusive));
return nonwrapping_range<U>::make_ending_with(interval_bound(std::forward<T>(val), exclusive));
case oper_t::LTE:
return nonwrapping_range<T>::make_ending_with(interval_bound(val, inclusive));
return nonwrapping_range<U>::make_ending_with(interval_bound(std::forward<T>(val), inclusive));
default:
throw std::logic_error(format("to_range: unknown comparison operator {}", op));
}
}
template nonwrapping_range<clustering_key_prefix> to_range(oper_t, const clustering_key_prefix&);
nonwrapping_range<clustering_key_prefix> to_range(oper_t op, const clustering_key_prefix& val) {
return to_range<const clustering_key_prefix&>(op, val);
}
value_set possible_lhs_values(const column_definition* cdef, const expression& expr, const query_options& options) {
const auto type = cdef ? get_value_comparator(cdef) : long_type.get();

View File

@@ -139,8 +139,7 @@ extern value_set possible_lhs_values(const column_definition*, const expression&
extern nonwrapping_range<bytes> to_range(const value_set&);
/// A range of all X such that X op val.
template<typename T>
nonwrapping_range<T> to_range(oper_t op, const T& val);
nonwrapping_range<clustering_key_prefix> to_range(oper_t op, const clustering_key_prefix& val);
/// True iff the index can support the entire expression.
extern bool is_supported_by(const expression&, const secondary_index::index&);