//          Copyright Carl Philipp Reh 2009 - 2021.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#ifndef FCPPT_OPTIONAL_ASSIGN_HPP_INCLUDED
#define FCPPT_OPTIONAL_ASSIGN_HPP_INCLUDED

#include <fcppt/optional/object_impl.hpp>
#include <fcppt/config/external_begin.hpp>
#include <type_traits>
#include <utility>
#include <fcppt/config/external_end.hpp>

namespace fcppt::optional
{
/**
\brief Assigns an optional and returns a reference to the optional's contents.

\ingroup fcpptoptional

Assigns \a _arg to \a _optional and returns a reference to \a _arg.
*/
template <typename Element, typename Arg>
[[nodiscard]] inline Element &assign(fcppt::optional::object<Element> &_optional, Arg &&_arg)
requires std::is_same_v<Element, std::remove_cv_t<Arg>>
{
  _optional = fcppt::optional::object<Element>(std::forward<Arg>(_arg));

  return _optional.get_unsafe();
}

}

#endif
