可以声明以下任一模板方法noexcept
吗?
template <typename T>
std::optional<T> foo(const T& value) // noexcept?
{
try {
// code possibly returning a T or a std::nullopt
} catch(...) {
return std::nullopt;
}
}
template <typename T>
boost::optional<T> bar(const T& value) // noexcept?
{
try {
// code possibly returning a T or a boost::none
} catch(...) {
return boost::none;
}
}
换句话说,未初始化的std/boost::optional
( nullopt/none
) 可以抛出吗?