/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2014-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#pragma once
#include <folly/ExceptionWrapper.h>
namespace folly {
-class TryException : public std::logic_error {
+class FOLLY_EXPORT TryException : public std::logic_error {
public:
using std::logic_error::logic_error;
};
-class UsingUninitializedTry : public TryException {
+class FOLLY_EXPORT UsingUninitializedTry : public TryException {
public:
UsingUninitializedTry() : TryException("Using uninitialized try") {}
};
*
* @returns mutable reference to the contained value
*/
- T& value()&;
+ T& value() &;
/*
* Get a rvalue reference to the contained value. If the Try contains an
* exception it will be rethrown.
*
* @returns rvalue reference to the contained value
*/
- T&& value()&&;
+ T&& value() &&;
/*
* Get a const reference to the contained value. If the Try contains an
* exception it will be rethrown.
*
* @returns const reference to the contained value
*/
- const T& value() const&;
+ const T& value() const &;
+ /*
+ * Get a const rvalue reference to the contained value. If the Try contains an
+ * exception it will be rethrown.
+ *
+ * @returns const rvalue reference to the contained value
+ */
+ const T&& value() const &&;
/*
* If the Try contains an exception, rethrow it. Otherwise do nothing.
*
* @returns const reference to the contained value
*/
- const T& operator*() const { return value(); }
+ const T& operator*() const & {
+ return value();
+ }
/*
* Dereference operator. If the Try contains an exception it will be rethrown.
*
* @returns mutable reference to the contained value
*/
- T& operator*() { return value(); }
+ T& operator*() & {
+ return value();
+ }
+ /*
+ * Mutable rvalue dereference operator. If the Try contains an exception it
+ * will be rethrown.
+ *
+ * @returns rvalue reference to the contained value
+ */
+ T&& operator*() && {
+ return std::move(value());
+ }
+ /*
+ * Const rvalue dereference operator. If the Try contains an exception it
+ * will be rethrown.
+ *
+ * @returns rvalue reference to the contained value
+ */
+ const T&& operator*() const && {
+ return std::move(value());
+ }
/*
* Const arrow operator. If the Try contains an exception it will be
Try<void>>::type
makeTryWith(F&& f);
-template <typename... Ts>
-std::tuple<Ts...> unwrapTryTuple(std::tuple<folly::Try<Ts>...>&& ts);
+/**
+ * Tuple<Try<Type>...> -> std::tuple<Type...>
+ *
+ * Unwraps a tuple-like type containing a sequence of Try<Type> instances to
+ * std::tuple<Type>
+ */
+template <typename Tuple>
+auto unwrapTryTuple(Tuple&&);
} // namespace folly