Files
scylladb/schema_mutations.hh
Kefu Chai f5b05cf981 treewide: use defaulted operator!=() and operator==()
in C++20, compiler generate operator!=() if the corresponding
operator==() is already defined, the language now understands
that the comparison is symmetric in the new standard.

fortunately, our operator!=() is always equivalent to
`! operator==()`, this matches the behavior of the default
generated operator!=(). so, in this change, all `operator!=`
are removed.

in addition to the defaulted operator!=, C++20 also brings to us
the defaulted operator==() -- it is able to generated the
operator==() if the member-wise lexicographical comparison.
under some circumstances, this is exactly what we need. so,
in this change, if the operator==() is also implemented as
a lexicographical comparison of all memeber variables of the
class/struct in question, it is implemented using the default
generated one by removing its body and mark the function as
`default`. moreover, if the class happen to have other comparison
operators which are implemented using lexicographical comparison,
the default generated `operator<=>` is used in place of
the defaulted `operator==`.

sometimes, we fail to mark the operator== with the `const`
specifier, in this change, to fulfil the need of C++ standard,
and to be more correct, the `const` specifier is added.

also, to generate the defaulted operator==, the operand should
be `const class_name&`, but it is not always the case, in the
class of `version`, we use `version` as the parameter type, to
fulfill the need of the C++ standard, the parameter type is
changed to `const version&` instead. this does not change
the semantic of the comparison operator. and is a more idiomatic
way to pass non-trivial struct as function parameters.

please note, because in C++20, both operator= and operator<=> are
symmetric, some of the operators in `multiprecision` are removed.
they are the symmetric form of the another variant. if they were
not removed, compiler would, for instance, find ambiguous
overloaded operator '=='.

this change is a cleanup to modernize the code base with C++20
features.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes #13687
2023-04-27 10:24:46 +03:00

139 lines
4.3 KiB
C++

/*
* Copyright 2015-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <vector>
#include "mutation/mutation.hh"
#include "schema/schema_fwd.hh"
#include "mutation/canonical_mutation.hh"
// Commutative representation of table schema
// Equality ignores tombstones.
class schema_mutations {
mutation _columnfamilies;
mutation _columns;
mutation_opt _view_virtual_columns;
mutation_opt _computed_columns;
mutation_opt _indices;
mutation_opt _dropped_columns;
mutation_opt _scylla_tables;
public:
schema_mutations(mutation columnfamilies, mutation columns, mutation_opt view_virtual_columns, mutation_opt computed_columns, mutation_opt indices, mutation_opt dropped_columns,
mutation_opt scylla_tables)
: _columnfamilies(std::move(columnfamilies))
, _columns(std::move(columns))
, _view_virtual_columns(std::move(view_virtual_columns))
, _computed_columns(std::move(computed_columns))
, _indices(std::move(indices))
, _dropped_columns(std::move(dropped_columns))
, _scylla_tables(std::move(scylla_tables))
{ }
schema_mutations(canonical_mutation columnfamilies,
canonical_mutation columns,
bool is_view,
std::optional<canonical_mutation> indices,
std::optional<canonical_mutation> dropped_columns,
std::optional<canonical_mutation> scylla_tables,
std::optional<canonical_mutation> view_virtual_columns,
std::optional<canonical_mutation> computed_columns);
schema_mutations(schema_mutations&&) = default;
schema_mutations& operator=(schema_mutations&&) = default;
schema_mutations(const schema_mutations&) = default;
schema_mutations& operator=(const schema_mutations&) = default;
void copy_to(std::vector<mutation>& dst) const;
const mutation& columnfamilies_mutation() const {
return _columnfamilies;
}
const mutation& columns_mutation() const {
return _columns;
}
const mutation_opt& view_virtual_columns_mutation() const {
return _view_virtual_columns;
}
const mutation_opt& computed_columns_mutation() const {
return _computed_columns;
}
const mutation_opt& scylla_tables() const {
return _scylla_tables;
}
mutation_opt& scylla_tables() {
return _scylla_tables;
}
const mutation_opt& indices_mutation() const {
return _indices;
}
const mutation_opt& dropped_columns_mutation() const {
return _dropped_columns;
}
canonical_mutation columnfamilies_canonical_mutation() const {
return canonical_mutation(_columnfamilies);
}
canonical_mutation columns_canonical_mutation() const {
return canonical_mutation(_columns);
}
std::optional<canonical_mutation> view_virtual_columns_canonical_mutation() const {
if (_view_virtual_columns) {
return canonical_mutation(*_view_virtual_columns);
}
return {};
}
std::optional<canonical_mutation> computed_columns_canonical_mutation() const {
if (_computed_columns) {
return canonical_mutation(*_computed_columns);
}
return {};
}
std::optional<canonical_mutation> indices_canonical_mutation() const {
if (_indices) {
return canonical_mutation(*_indices);
}
return {};
}
std::optional<canonical_mutation> dropped_columns_canonical_mutation() const {
if (_dropped_columns) {
return canonical_mutation(*_dropped_columns);
}
return {};
}
std::optional<canonical_mutation> scylla_tables_canonical_mutation() const {
if (_scylla_tables) {
return canonical_mutation(*_scylla_tables);
}
return {};
}
bool is_view() const;
table_schema_version digest() const;
std::optional<sstring> partitioner() const;
bool operator==(const schema_mutations&) const;
schema_mutations& operator+=(schema_mutations&&);
// Returns true iff any mutations contain any live cells
bool live() const;
friend std::ostream& operator<<(std::ostream&, const schema_mutations&);
};