summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchcommon/common/undefinedvalues.h
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib/src/vespa/searchcommon/common/undefinedvalues.h')
-rw-r--r--searchlib/src/vespa/searchcommon/common/undefinedvalues.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchcommon/common/undefinedvalues.h b/searchlib/src/vespa/searchcommon/common/undefinedvalues.h
new file mode 100644
index 00000000000..bbe3198a8dc
--- /dev/null
+++ b/searchlib/src/vespa/searchcommon/common/undefinedvalues.h
@@ -0,0 +1,69 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <cmath>
+#include <limits>
+#include <vespa/vespalib/stllike/string.h>
+
+namespace search::attribute {
+
+// for all integers
+template <typename T>
+constexpr T getUndefined() {
+ return std::numeric_limits<T>::min();
+}
+
+template <>
+inline constexpr float getUndefined<float>() {
+ return -std::numeric_limits<float>::quiet_NaN();
+}
+
+template <>
+inline constexpr double getUndefined<double>() {
+ return -std::numeric_limits<double>::quiet_NaN();
+}
+
+
+// for all signed integers
+template <typename T>
+bool isUndefined(const T & value) {
+ return value == getUndefined<T>();
+}
+
+template <>
+inline bool isUndefined<uint8_t>(const uint8_t &) {
+ return false;
+}
+
+template <>
+inline bool isUndefined<uint16_t>(const uint16_t &) {
+ return false;
+}
+
+template <>
+inline bool isUndefined<uint32_t>(const uint32_t &) {
+ return false;
+}
+
+template <>
+inline bool isUndefined<uint64_t>(const uint64_t &) {
+ return false;
+}
+
+template <>
+inline bool isUndefined<float>(const float & value) {
+ return std::isnan(value);
+}
+
+template <>
+inline bool isUndefined<double>(const double & value) {
+ return std::isnan(value);
+}
+
+template <>
+inline bool isUndefined<vespalib::string>(const vespalib::string & value) {
+ return value.empty();
+}
+
+}