aboutsummaryrefslogtreecommitdiffstats
path: root/searchcommon
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-04-09 14:34:13 +0200
committerTor Egge <Tor.Egge@online.no>2022-04-09 14:34:13 +0200
commit7eeec7b951b45e5d6bfc555b68cb1bc9f3fa8b46 (patch)
tree80d5b3afdae8baf862bd68085d766ac063d75e0e /searchcommon
parent80b96d32550ae0df59572a58cd62f507e8068c2c (diff)
Trim down search::multivalue::Value and search::multivalue::WeightedValue.
Use traits to check for presence of a weight and to extract inner type.
Diffstat (limited to 'searchcommon')
-rw-r--r--searchcommon/src/vespa/searchcommon/attribute/multi_value_traits.h42
-rw-r--r--searchcommon/src/vespa/searchcommon/attribute/multivalue.h10
2 files changed, 42 insertions, 10 deletions
diff --git a/searchcommon/src/vespa/searchcommon/attribute/multi_value_traits.h b/searchcommon/src/vespa/searchcommon/attribute/multi_value_traits.h
new file mode 100644
index 00000000000..fcb3f1bd33a
--- /dev/null
+++ b/searchcommon/src/vespa/searchcommon/attribute/multi_value_traits.h
@@ -0,0 +1,42 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <type_traits>
+
+namespace search::multivalue {
+
+template <typename T> class Value;
+template <typename T> class WeightedValue;
+
+/*
+ * Check for the presence of a weight.
+ */
+template <typename T>
+struct is_WeightedValue;
+
+template <typename T>
+struct is_WeightedValue<Value<T>> : std::false_type {};
+
+template <typename T>
+struct is_WeightedValue<WeightedValue<T>> : std::true_type {};
+
+template <typename T>
+inline constexpr bool is_WeightedValue_v = is_WeightedValue<T>::value;
+
+/*
+ * Extract inner type.
+ */
+template <typename T>
+struct ValueType;
+
+template <typename T>
+struct ValueType<Value<T>> { using type = T; };
+
+template <typename T>
+struct ValueType<WeightedValue<T>> { using type = T; };
+
+template <typename T>
+using ValueType_t = typename ValueType<T>::type;
+
+}
diff --git a/searchcommon/src/vespa/searchcommon/attribute/multivalue.h b/searchcommon/src/vespa/searchcommon/attribute/multivalue.h
index 780e8627b91..0783338c6f6 100644
--- a/searchcommon/src/vespa/searchcommon/attribute/multivalue.h
+++ b/searchcommon/src/vespa/searchcommon/attribute/multivalue.h
@@ -9,7 +9,6 @@ namespace search::multivalue {
template <typename T>
class Value {
public:
- typedef T ValueType;
Value() noexcept : _v() {}
Value(T v) noexcept : _v(v) { }
Value(T v, int32_t w) noexcept : _v(v) { (void) w; }
@@ -20,13 +19,9 @@ public:
operator T & () { return _v; }
int32_t weight() const { return 1; }
void setWeight(int32_t w) { (void) w; }
- void incWeight(int32_t w) { (void) w; }
bool operator ==(const Value<T> & rhs) const { return _v == rhs._v; }
bool operator <(const Value<T> & rhs) const { return _v < rhs._v; }
bool operator >(const Value<T> & rhs) const { return _v > rhs._v; }
- static bool hasWeight() { return false; }
-
- static constexpr bool _hasWeight = false;
private:
T _v;
};
@@ -34,7 +29,6 @@ private:
template <typename T>
class WeightedValue {
public:
- typedef T ValueType;
WeightedValue() noexcept : _v(), _w(1) { }
WeightedValue(T v, int32_t w) noexcept : _v(v), _w(w) { }
T value() const { return _v; }
@@ -44,14 +38,10 @@ public:
operator T & () { return _v; }
int32_t weight() const { return _w; }
void setWeight(int32_t w) { _w = w; }
- void incWeight(int32_t w) { _w += w; }
bool operator==(const WeightedValue<T> & rhs) const { return _v == rhs._v; }
bool operator <(const WeightedValue<T> & rhs) const { return _v < rhs._v; }
bool operator >(const WeightedValue<T> & rhs) const { return _v > rhs._v; }
- static bool hasWeight() { return true; }
-
- static constexpr bool _hasWeight = true;
private:
T _v;
int32_t _w;