From 3e400cf54eafdfe0be39183ee6569d31f50abc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Botond=20D=C3=A9nes?= Date: Wed, 6 May 2020 12:39:20 +0300 Subject: [PATCH] compound_type: fix const correctness Make all methods that don't mutate members const. --- compound.hh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/compound.hh b/compound.hh index f4a60d021f..824aae09d1 100644 --- a/compound.hh +++ b/compound.hh @@ -91,7 +91,7 @@ private: return len; } public: - bytes serialize_single(bytes&& v) { + bytes serialize_single(bytes&& v) const { return serialize_value({std::move(v)}); } template @@ -109,7 +109,7 @@ public: static bytes serialize_value(std::initializer_list values) { return serialize_value(boost::make_iterator_range(values.begin(), values.end())); } - bytes serialize_optionals(const std::vector& values) { + bytes serialize_optionals(const std::vector& values) const { return serialize_value(values | boost::adaptors::transformed([] (const bytes_opt& bo) -> bytes_view { if (!bo) { throw std::logic_error("attempted to create key component from empty optional"); @@ -117,7 +117,7 @@ public: return *bo; })); } - bytes serialize_value_deep(const std::vector& values) { + bytes serialize_value_deep(const std::vector& values) const { // TODO: Optimize std::vector partial; partial.reserve(values.size()); @@ -128,7 +128,7 @@ public: } return serialize_value(partial); } - bytes decompose_value(const value_type& values) { + bytes decompose_value(const value_type& values) const { return serialize_value(values); } class iterator : public std::iterator { @@ -180,7 +180,7 @@ public: static boost::iterator_range components(const bytes_view& v) { return { begin(v), end(v) }; } - value_type deserialize_value(bytes_view v) { + value_type deserialize_value(bytes_view v) const { std::vector result; result.reserve(_types.size()); std::transform(begin(v), end(v), std::back_inserter(result), [] (auto&& v) { @@ -188,10 +188,10 @@ public: }); return result; } - bool less(bytes_view b1, bytes_view b2) { + bool less(bytes_view b1, bytes_view b2) const { return compare(b1, b2) < 0; } - size_t hash(bytes_view v) { + size_t hash(bytes_view v) const { if (_byte_order_equal) { return std::hash()(v); } @@ -203,7 +203,7 @@ public: } return h; } - int compare(bytes_view b1, bytes_view b2) { + int compare(bytes_view b1, bytes_view b2) const { if (_byte_order_comparable) { if (_is_reversed) { return compare_unsigned(b2, b1); @@ -224,11 +224,11 @@ public: bool is_empty(bytes_view v) const { return begin(v) == end(v); } - void validate(bytes_view v) { + void validate(bytes_view v) const { // FIXME: implement warn(unimplemented::cause::VALIDATION); } - bool equal(bytes_view v1, bytes_view v2) { + bool equal(bytes_view v1, bytes_view v2) const { if (_byte_order_equal) { return compare_unsigned(v1, v2) == 0; }