`typename std :: remove_reference `和`constexpr typename std :: remove_reference `

问题描述 投票:0回答:1

根据文档(https://en.cppreference.com/w/cpp/utility/move),std::move<T>有两种构造函数,在下面发布。

这些构造函数之间有什么区别?最让我困惑的是,为什么第二个构造函数中需要关键字(typename)。

我是C ++的新手。对于这个问题的任何提示,我将不胜感激。

template< class T >
typename std::remove_reference<T>::type&& move( T&& t ) noexcept;    (since C++11)     (until C++14)
template< class T >
constexpr typename std::remove_reference<T>::type&& move( T&& t ) noexcept;    (since C++14)
c++ c++11 constructor move typename
1个回答
0
投票
[...]有std::move<T> ...]的两种构造函数
否,它们不是构造函数,而是std::move的函数签名。一个在C ++ 14之前,第二个在C ++ 14之后。

在第二个中是specifier constexpr is used,意思是

constexpr-指定

变量或函数的值可以

出现在常量表达式中

在此处阅读更多:constexpr


最让我感到困惑的是,为什么在其中需要关键字(What are 'constexpr' useful for?)第二个构造函数。
根据typenamecppreference.com有一个辅助类型,因为C ++ 14

std::remove_reference

因此在第二个中应该是

template< class T >
using remove_reference_t = typename remove_reference<T>::type;  (since C++14)
© www.soinside.com 2019 - 2024. All rights reserved.