Skip to content

Instantly share code, notes, and snippets.

@Naios
Created April 25, 2015 20:37
Show Gist options
  • Save Naios/54ccbd129839f460a614 to your computer and use it in GitHub Desktop.
Save Naios/54ccbd129839f460a614 to your computer and use it in GitHub Desktop.
Archive of code pieces
//! Returns an optional created from the given value.
template <typename T>
inline typename std::enable_if<!std::is_rvalue_reference<T>::value, Optional<T>>::type
make_optional(typename std::decay<T>::type const& value)
{
return Optional<T>(value);
}
//! Returns an optional created from the given moved value.
template <typename T>
inline typename std::enable_if<std::is_rvalue_reference<T>::value, Optional<T>>::type
make_optional(typename std::decay<T>::type&& value)
{
return Optional<T>(std::forward<typename std::decay<T>::type>(value));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment