/*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* @author Tudor Bosman (tudorb@fb.com)
*/
-#ifndef FOLLY_DISCRIMINATEDPTR_H_
-#define FOLLY_DISCRIMINATEDPTR_H_
+#pragma once
#include <limits>
#include <stdexcept>
+
#include <glog/logging.h>
+
#include <folly/Likely.h>
#include <folly/Portability.h>
#include <folly/detail/DiscriminatedPtrDetail.h>
-#if !FOLLY_X64
-# error "DiscriminatedPtr is x64-specific code."
+#if !FOLLY_X64 && !FOLLY_AARCH64 && !FOLLY_PPC64
+# error "DiscriminatedPtr is x64, arm64 and ppc64 specific code."
#endif
namespace folly {
* Get the 1-based type index of T in Types.
*/
template <typename T>
- size_t typeIndex() const {
- return dptr_detail::GetTypeIndex<T, Types...>::value;
+ uint16_t typeIndex() const {
+ return uint16_t(dptr_detail::GetTypeIndex<T, Types...>::value);
}
uint16_t index() const { return data_ >> 48; }
uintptr_t data_;
};
-} // namespace folly
-
-#endif /* FOLLY_DISCRIMINATEDPTR_H_ */
+template <typename Visitor, typename... Args>
+decltype(auto) apply_visitor(
+ Visitor&& visitor,
+ const DiscriminatedPtr<Args...>& variant) {
+ return variant.apply(std::forward<Visitor>(visitor));
+}
+
+template <typename Visitor, typename... Args>
+decltype(auto) apply_visitor(
+ Visitor&& visitor,
+ DiscriminatedPtr<Args...>& variant) {
+ return variant.apply(std::forward<Visitor>(visitor));
+}
+
+template <typename Visitor, typename... Args>
+decltype(auto) apply_visitor(
+ Visitor&& visitor,
+ DiscriminatedPtr<Args...>&& variant) {
+ return variant.apply(std::forward<Visitor>(visitor));
+}
+
+} // namespace folly