Skip to content

Commit

Permalink
Merge pull request #22096 from vespa-engine/toregge/change-multivalue…
Browse files Browse the repository at this point in the history
…-value-from-class-to-using-statement

Change search::multivalue::Value from class to using statement.
  • Loading branch information
geirst authored Apr 11, 2022
2 parents efb1d9c + e58ce1f commit 929401b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@

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 {};
struct is_WeightedValue : std::false_type {};

template <typename T>
struct is_WeightedValue<WeightedValue<T>> : std::true_type {};
Expand All @@ -28,10 +24,7 @@ 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; };
struct ValueType { using type = T; };

template <typename T>
struct ValueType<WeightedValue<T>> { using type = T; };
Expand Down
31 changes: 7 additions & 24 deletions searchcommon/src/vespa/searchcommon/attribute/multivalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,7 @@
namespace search::multivalue {

template <typename T>
class Value {
public:
Value() noexcept : _v() {}
Value(T v) noexcept : _v(v) { }
T value() const noexcept { return _v; }
const T& value_ref() const noexcept { return _v; }
T& value_ref() noexcept { return _v; }
operator T () const noexcept { return _v; }
operator T & () noexcept { return _v; }
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; }
private:
T _v;
};
using Value = T;

template <typename T>
class WeightedValue {
Expand All @@ -44,36 +30,33 @@ class WeightedValue {
};

template <typename T>
inline int32_t get_weight(const Value<T>&) noexcept { return 1; }
inline int32_t get_weight(const T&) noexcept { return 1; }

template <typename T>
inline int32_t get_weight(const WeightedValue<T>& value) noexcept { return value.weight(); }

template <typename T>
inline T get_value(const Value<T> &value) noexcept { return value.value(); }
inline T get_value(const T& value) noexcept { return value; }

template <typename T>
inline T get_value(const WeightedValue<T>& value) noexcept { return value.value(); }

template <typename T>
inline const T& get_value_ref(const Value<T> &value) noexcept { return value.value_ref(); }
inline const T& get_value_ref(const T& value) noexcept { return value; }

template <typename T>
inline const T& get_value_ref(const WeightedValue<T>& value) noexcept { return value.value_ref(); }

template <typename T>
inline T& get_value_ref(Value<T> &value) noexcept { return value.value_ref(); }
inline T& get_value_ref(T& value) noexcept { return value; }

template <typename T>
inline T& get_value_ref(WeightedValue<T>& value) noexcept { return value.value_ref(); }

template <typename M>
struct ValueBuilder;

template <typename T>
struct ValueBuilder<Value<T>>
struct ValueBuilder
{
static Value<T> build(T value, int32_t) noexcept { return Value<T>(value); }
static M build(M value, int32_t) noexcept { return value; }
};

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions searchlib/src/vespa/searchlib/features/dotproductfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ DotProductByContentFillExecutor<BaseType>::~DotProductByContentFillExecutor() =

namespace {

template<typename T> struct IsNonWeightedType : std::false_type {};
template<typename BaseType> struct IsNonWeightedType<multivalue::Value<BaseType>> : std::true_type {};
template<typename T> struct IsNonWeightedType : std::true_type {};
template<typename BaseType> struct IsNonWeightedType<multivalue::WeightedValue<BaseType>> : std::false_type {};

// Compile-time sanity check for type compatibility of gnarly BaseType <-> multivalue::Value
// reinterpret_cast used by some getAttributeValues calls.
Expand Down

0 comments on commit 929401b

Please sign in to comment.