C++17
fold expression
std::size
version 1 :
template <class C>
constexpr auto size(const C& c) -> decltype(c.size())
{
return c.size();
}
version 2 :
template <class T, std::size_t N>
constexpr std::size_t size(const T (&array)[N]) noexcept
{
return N;
}
Progress
參考
Descriptions of C++17 features, presented mostly in “Tony Tables”
- What is Strict Aliasing and Why do we Care?
C 有 effective type 和 compatible type,但是 C++ 沒有
C++ 有 dynamic type 和 similar type,但是 C 沒有
Type Punning