Hi I am looking at one of std::optional
implementations here at here and I have found this code snippet confuses me:
// workaround: std utility functions aren't constexpr yet
template <class T> inline constexpr T&& constexpr_forward(typename
std::remove_reference<T>::type& t) noexcept
{
return static_cast<T&&>(t);
}
So I don't understand this in the following way:
- What does
typename
do here? Just to declare the following part is a type? - Why do we need
std::remove_reference
here? Didn't we add the reference back in thetype&
part? - What does "std utility functions are not constexpr yet" mean? How does this function make them constexpr? The body of it is just a
static_cast
. - This function is used in a number of constructors and it looks like this:
template <class... Args> constexpr storage_t( Args&&... args ) : value_(constexpr_forward<Args>(args)...) {}
, so what does it do here to args?
Thanks a lot.
Aucun commentaire:
Enregistrer un commentaire