cpp-common/bt2c: use `ComparableWithCStringView` on `operator!=` meant for `CStringView`
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 1 Mar 2024 15:42:13 +0000 (10:42 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Mar 2024 18:56:36 +0000 (14:56 -0400)
I don't recall exactly when I needed this, but it occured to me once
that the `operator!=` we provide for `CStringView` was getting picked up
for some unrelated type.  It just seems dangerous to provide a generic
templated operator like that that can match literally anything.

Use the same `ComparableWithCStringView` conditions here that we use for
`operator==` just above, so that it only gets used for what it was
intended for.

Change-Id: I798f1c8195c541f6188499dcfabfe1233a95a492
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11962
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common/bt2c/c-string-view.hpp

index b1a7b6e76d4037fb2976f1248a1a26d4278d822c..3dca0299da4babf6495d26b88905126feb7104ab 100644 (file)
@@ -240,7 +240,10 @@ bool operator==(LhsT&& lhs, RhsT&& rhs) noexcept
  *
  * Both `lhs` and `rhs` must not have an underlying `nullptr` raw data.
  */
-template <typename LhsT, typename RhsT>
+template <
+    typename LhsT, typename RhsT,
+    typename = typename std::enable_if<internal::ComparableWithCStringView<LhsT>::value>::type,
+    typename = typename std::enable_if<internal::ComparableWithCStringView<RhsT>::value>::type>
 bool operator!=(LhsT&& lhs, RhsT&& rhs) noexcept
 {
     return !(std::forward<LhsT>(lhs) == std::forward<RhsT>(rhs));
This page took 0.025346 seconds and 4 git commands to generate.