喜歡這篇文章嗎?喜歡的話去看博主的置頂博客,即可依據分類找到此文章的原版得到更好的體驗,
圖片及代碼顯示的問題,筆者深感抱歉,想要更好的體驗去原博文即可。
title: Boost 源碼分析筆記7 - decay
mathjax: true
date: 2020-03-17 16:41:19
categories: [c++筆記,Boost源碼分析筆記]
tags: [c++筆記,Boost源碼分析筆記]
keywords: [c++筆記,Boost源碼分析筆記]
這篇博客要求提前知道
{% post_link ‘Boost-源碼分析筆記2-is-array’ is_array %}
{% post_link ‘Boost-源碼分析筆記4-is-function’ is_function%}
{% post_link ‘Boost-源碼分析筆記5-remove-bounds’ remove_bounds%}
{% post_link ‘Boost-源碼分析筆記6-remove-reference’ remove_reference%}
{% post_link ‘Boost-源碼分析筆記1-remove-cv’ remove_cv%}
decay
這個模版元的意思是移除引用、移除const、移除volatile、數組移除範圍、函數變成指針。
namespace detail
{
template <class T, bool Array, bool Function> struct decay_imp { typedef typename remove_cv<T>::type type; };
template <class T> struct decay_imp<T, true, false> { typedef typename remove_bounds<T>::type* type; };
template <class T> struct decay_imp<T, false, true> { typedef T* type; };
}
template< class T >
struct decay
{
private:
typedef typename remove_reference<T>::type Ty;
public:
typedef typename boost::detail::decay_imp<Ty, boost::is_array<Ty>::value, boost::is_function<Ty>::value>::type type;
};
實際上做起來的時候是先移除引用,最後移除cv的。