folly/folly/Try-inl.h

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <folly/Utility.h>
#include <folly/functional/Invoke.h>

#include <stdexcept>
#include <tuple>
#include <utility>

namespace folly {

namespace detail {
template <class T>
TryBase<T>::TryBase(TryBase<T>&& t) noexcept(
    std::is_nothrow_move_constructible<T>::value)
    :{}

template <class T>
TryBase<T>& TryBase<T>::operator=(TryBase<T>&& t) noexcept(
    std::is_nothrow_move_constructible<T>::value) {}

template <class T>
TryBase<T>::TryBase(const TryBase<T>& t) noexcept(
    std::is_nothrow_copy_constructible<T>::value) {}

template <class T>
TryBase<T>& TryBase<T>::operator=(const TryBase<T>& t) noexcept(
    std::is_nothrow_copy_constructible<T>::value) {}

template <class T>
void TryBase<T>::destroy() noexcept {}

template <class T>
template <class T2>
TryBase<T>::TryBase(typename std::enable_if<
                    std::is_same<Unit, T2>::value,
                    Try<void> const&>::type t) noexcept
    : contains_(Contains::NOTHING) {}

template <class T>
TryBase<T>::~TryBase() {}

} // namespace detail

Try<void>::Try(const Try<Unit>& t) noexcept :{}

template <typename T>
template <typename... Args>
T& Try<T>::emplace(Args&&... args) noexcept(
    std::is_nothrow_constructible<T, Args&&...>::value) {}

template <typename T>
template <typename... Args>
exception_wrapper& Try<T>::emplaceException(Args&&... args) noexcept(
    std::is_nothrow_constructible<exception_wrapper, Args&&...>::value) {}

template <class T>
T& Try<T>::value() & {}

template <class T>
T&& Try<T>::value() && {}

template <class T>
const T& Try<T>::value() const& {}

template <class T>
const T&& Try<T>::value() const&& {}

template <class T>
template <class U>
T Try<T>::value_or(U&& defaultValue) const& {}

template <class T>
template <class U>
T Try<T>::value_or(U&& defaultValue) && {}

template <class T>
void Try<T>::throwUnlessValue() const {}

template <class T>
void Try<T>::throwIfFailed() const {}

Try<void>& Try<void>::operator=(const Try<void>& t) noexcept {}

template <typename... Args>
exception_wrapper& Try<void>::emplaceException(Args&&... args) noexcept(
    std::is_nothrow_constructible<exception_wrapper, Args&&...>::value) {}

void Try<void>::throwIfFailed() const {}

void Try<void>::throwUnlessValue() const {}

template <typename F>
typename std::enable_if<
    !std::is_same<invoke_result_t<F>, void>::value,
    Try<invoke_result_t<F>>>::type
makeTryWithNoUnwrap(F&& f) {}

template <typename F>
typename std::
    enable_if<std::is_same<invoke_result_t<F>, void>::value, Try<void>>::type
    makeTryWithNoUnwrap(F&& f) {}

template <typename F>
typename std::
    enable_if<!isTry<invoke_result_t<F>>::value, Try<invoke_result_t<F>>>::type
    makeTryWith(F&& f) {}

template <typename F>
typename std::enable_if<isTry<invoke_result_t<F>>::value, invoke_result_t<F>>::
    type
    makeTryWith(F&& f) {}

template <typename T, typename... Args>
T* tryEmplace(Try<T>& t, Args&&... args) noexcept {}

void tryEmplace(Try<void>& t) noexcept {}

template <typename T, typename Func>
T* tryEmplaceWith(Try<T>& t, Func&& func) noexcept {}

template <typename Func>
bool tryEmplaceWith(Try<void>& t, Func&& func) noexcept {}

namespace try_detail {

/**
 * Trait that removes the layer of Try abstractions from the passed in type
 */
template <typename Type>
struct RemoveTry;
RemoveTry<TupleType<folly::Try<Types>...>>;

template <std::size_t... Indices, typename Tuple>
auto unwrapTryTupleImpl(std::index_sequence<Indices...>, Tuple&& instance) {}
} // namespace try_detail

template <typename Tuple>
auto unwrapTryTuple(Tuple&& instance) {}

template <typename T>
void tryAssign(Try<T>& t, Try<T>&& other) noexcept {}

// limited to the instances unconditionally forced by the futures library
extern template class Try<Unit>;

} // namespace folly