summaryrefslogtreecommitdiffstats
path: root/searchcommon
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahooinc.com>2022-04-11 16:18:26 +0200
committerTor Egge <Tor.Egge@yahooinc.com>2022-04-11 16:42:19 +0200
commit1386f7094eaf75a9ed77f081293960f708c1bb7a (patch)
tree7d2e2fac94d4388da0cb9268ac643521d88f37ac /searchcommon
parenta6f0ef3e995ce8ef0d34a533f37910c6e7c0934a (diff)
Remove weight() member function from multivalue::Value
Diffstat (limited to 'searchcommon')
-rw-r--r--searchcommon/src/vespa/searchcommon/attribute/multivalue.h25
1 files changed, 22 insertions, 3 deletions
diff --git a/searchcommon/src/vespa/searchcommon/attribute/multivalue.h b/searchcommon/src/vespa/searchcommon/attribute/multivalue.h
index b9e85480d2d..b5799b9f3d2 100644
--- a/searchcommon/src/vespa/searchcommon/attribute/multivalue.h
+++ b/searchcommon/src/vespa/searchcommon/attribute/multivalue.h
@@ -11,13 +11,11 @@ class Value {
public:
Value() noexcept : _v() {}
Value(T v) noexcept : _v(v) { }
- Value(T v, int32_t w) noexcept : _v(v) { (void) w; }
T value() const { return _v; }
const T& value_ref() const { return _v; }
T& value_ref() { return _v; }
operator T () const { return _v; }
operator T & () { return _v; }
- int32_t weight() const { return 1; }
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; }
@@ -35,7 +33,7 @@ public:
T& value_ref() { return _v; }
operator T () const { return _v; }
operator T & () { return _v; }
- int32_t weight() const { return _w; }
+ int32_t weight() const noexcept { return _w; }
bool operator==(const WeightedValue<T> & rhs) const { return _v == rhs._v; }
bool operator <(const WeightedValue<T> & rhs) const { return _v < rhs._v; }
@@ -45,4 +43,25 @@ private:
int32_t _w;
};
+template <typename T>
+inline int32_t get_weight(const Value<T>&) noexcept { return 1; }
+
+template <typename T>
+inline int32_t get_weight(const WeightedValue<T>& value) noexcept { return value.weight(); }
+
+template <typename M>
+struct ValueBuilder;
+
+template <typename T>
+struct ValueBuilder<Value<T>>
+{
+ static Value<T> build(T value, int32_t) noexcept { return Value<T>(value); }
+};
+
+template <typename T>
+struct ValueBuilder<WeightedValue<T>>
+{
+ static WeightedValue<T> build(T value, int32_t weight) noexcept { return WeightedValue<T>(value, weight); }
+};
+
}