Using the BOOST_AUTO
macro we can emulate the auto
keyword that isn't available before C++11:
BOOST_AUTO( var, 1 + 2 ); // int var = 3
auto var = 1 + 2; // the same in C++11
Is there any way to emulate const auto
?
const auto var = 1 + 2; // const int var = 3
You can just include the "trailing" const:
#include <boost/typeof/typeof.hpp>
int main()
{
BOOST_AUTO(const x, 42);
static_assert(std::is_const<decltype(x)>(), "weehoo");
}
The trailing position is the only consistent position for the const
qualifier for many reasons. This is one of them :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With