redpanda
redpanda copied to clipboard
named_type: forbid arithmetic operations between unrelated named_types
explicitly forbids operations like
named_type<int, struct tag_a>(1) + named_type<int, struct tag_b>(1)
The expression worked because there is an implicit conversion possible from named_type<int, tag> to int, and an operator+(int).
this pr deletes the generic base_named_type from the arithmetic operators overload set and implicitly forbids the above case to compile.
operations like
named_type<int>(1) + 1
are still allowed. see named_type_test.cc
template<typename Lhs, typename Rhs>
concept arithmetic_ready = requires(Lhs l, Rhs r) {
l + r;
l - r;
l += r;
};
static_assert(arithmetic_ready<named_int, named_int>);
static_assert(arithmetic_ready<named_int, int>);
static_assert(
!arithmetic_ready<named_int, named_type<int, struct another_tag_t>>);
Backports Required
- [ ] none - not a bug fix
- [ ] none - this is a backport
- [ ] none - issue does not exist in previous branches
- [x] none - papercut/not impactful enough to backport
- [ ] v23.2.x
- [ ] v23.1.x
- [ ] v22.3.x
Release Notes
- none