Chapter 4, Compile-time Tricks, and Chapter 8, Metaprogramming, were devoted to metaprogramming. If you were trying to use techniques from those chapters, you may have noticed that writing a metafunction can take a lot of time. So, it may be a good idea to experiment with metafunctions using more user-friendly methods, such as C++11 constexpr
, before writing a portable implementation.
In this recipe, we'll take a look at how to detect constexpr
support.
The constexpr
functions are functions that can be evaluated at compile-time. That is all we need to know for this recipe.
Let's see how we can detect compiler support for the constexpr
feature:
- Just like in other recipes from this chapter, we start with the following header:
#include <boost/config.hpp>
- Write the
constexpr
function:
#if !defined(BOOST_NO_CXX11_CONSTEXPR) \ && !defined(BOOST_NO_CXX11_HDR_ARRAY) template <class T> constexpr int get_size...