contrib/fuzz/fuzzutil.h
changeset 38174 36d55f90e2a3
parent 38173 fa0ddd5e8fff
child 43615 6f5c352f41b6
--- a/contrib/fuzz/fuzzutil.h	Sat Apr 28 22:18:50 2018 -0400
+++ b/contrib/fuzz/fuzzutil.h	Mon Apr 30 22:02:07 2018 -0400
@@ -2,8 +2,31 @@
 #define CONTRIB_FUZZ_FUZZUTIL_H
 #include <iostream>
 #include <memory>
+#include <stdint.h>
+
+/* Try and use std::optional, but failing that assume we'll have a
+ * workable https://abseil.io/ install on the include path to get
+ * their backport of std::optional. */
+#ifdef __has_include
+#if __has_include(<optional>) && __cplusplus >= 201703L
 #include <optional>
-#include <stdint.h>
+#define CONTRIB_FUZZ_HAVE_STD_OPTIONAL
+#endif
+#endif
+#ifdef CONTRIB_FUZZ_HAVE_STD_OPTIONAL
+namespace contrib
+{
+using std::nullopt;
+using std::optional;
+} /* namespace contrib */
+#else
+#include "third_party/absl/types/optional.h"
+namespace contrib
+{
+using absl::nullopt;
+using absl::optional;
+} /* namespace contrib */
+#endif
 
 /* set DEBUG to 1 for a few debugging prints, or 2 for a lot */
 #define DEBUG 0
@@ -19,6 +42,6 @@
 };
 
 /* Split a non-zero-length input into two inputs. */
-std::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size);
+contrib::optional<two_inputs> SplitInputs(const uint8_t *Data, size_t Size);
 
 #endif /* CONTRIB_FUZZ_FUZZUTIL_H */