summaryrefslogtreecommitdiff
path: root/libadhocutil/optionals.h
diff options
context:
space:
mode:
Diffstat (limited to 'libadhocutil/optionals.h')
-rw-r--r--libadhocutil/optionals.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/libadhocutil/optionals.h b/libadhocutil/optionals.h
new file mode 100644
index 0000000..f4d6b1a
--- /dev/null
+++ b/libadhocutil/optionals.h
@@ -0,0 +1,30 @@
+#ifndef ADHOCUTIL_OPTIONALS_H
+#define ADHOCUTIL_OPTIONALS_H
+
+#include <type_traits>
+
+namespace AdHoc {
+ template <typename A, typename B>
+ auto
+ operator/(const A & a, const B & b) -> typename std::enable_if<
+ std::is_constructible<bool, A>::value &&
+ !std::is_pointer<B>::value &&
+ std::is_convertible<decltype(*a), B>::value,
+ decltype(a ? *a : b)>::type
+ {
+ return (a ? *a : b);
+ }
+
+ template <typename A, typename B>
+ auto
+ operator/(const A & a, const B & b) -> typename std::enable_if<
+ std::is_constructible<bool, A>::value &&
+ std::is_pointer<B>::value,
+ decltype(a ? &*a : b)>::type
+ {
+ return (a ? &*a : b);
+ }
+}
+
+#endif
+