[問題] 關於boost::ref()的疑問?
目前正在練習boost的一些範例 有關理解boost的實做上有點疑問
範例是這樣~
struct TEST
{
int k;
};
template <typename T> int foo(T a)
{
typedef boost::unwrap_reference<T>::type& truetype;
truetype k = a;
return 0;
}
int main
{
TEST test1;
foo(boost::ref(test1));
}
有問題的部份是 這一段code
typedef boost::unwrap_reference<T>::type& truetype;
根據範例的code 這段依該是會complie成
boost::unwrap_reference<reference_wrapper<TEST> >::type& truetype;
根據boost的原始碼 ref.hpp
template<class T> class reference_wrapper
{
public:
typedef T type;
...
...
}
template<typename T>
class unwrap_reference
{
public:
typedef T type;
};
我認為 truetype 這個型別應該是
reference_wrapper<TEST>&
但是執行結果卻是
TEST& 這個型別
感覺上 reference_wrapper<TEST>& 又偷偷轉成
reference_wrapper<TEST>::type&
想問一下為什麼型別是變成 TEST& 而不是我想的 reference_wrapper<TEST>&
搞不清楚的問題 想問問有研究的版眾~
感謝大家~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.120.189.231
→
04/27 23:46, , 1F
04/27 23:46, 1F
→
04/27 23:47, , 2F
04/27 23:47, 2F
→
04/28 00:12, , 3F
04/28 00:12, 3F
→
04/28 00:25, , 4F
04/28 00:25, 4F