[英]How to emulate 'const auto' with BOOST_AUTO in C++?
使用BOOST_AUTO
宏,我們可以模擬在C ++ 11之前不可用的auto
關鍵字:
BOOST_AUTO( var, 1 + 2 ); // int var = 3
auto var = 1 + 2; // the same in C++11
有沒有辦法模擬const auto
?
const auto var = 1 + 2; // const int var = 3
你可以只包括“尾隨”const:
#include <boost/typeof/typeof.hpp>
int main()
{
BOOST_AUTO(const x, 42);
static_assert(std::is_const<decltype(x)>(), "weehoo");
}
由於許多原因,尾隨位置是const
限定符的唯一一致位置。 這是其中之一:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.