dimanche 16 juillet 2017

What does const_forward do in optional implementation in C++?

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:

  1. What does typename do here? Just to declare the following part is a type?
  2. Why do we need std::remove_reference here? Didn't we add the reference back in the type& part?
  3. 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.
  4. 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