获取大小std ::数组没有实例
给定这个结构:
struct Foo { std::array<int, 8> bar; };  如果我没有Foo的实例,我怎样才能得到bar数组元素的数量? 
 你可以使用std::tuple_size : 
 std::tuple_size<decltype(Foo::bar)>::value 
 尽pipe@ Jarod42的好的答案 ,这里是另一种基于decltype解决scheme,不使用tuple_size 。 
 它遵循一个在C ++ 11中工作的最小的工作示例: 
 #include<array> struct Foo { std::array<int, 8> bar; }; int main() { constexpr std::size_t N = decltype(Foo::bar){}.size(); static_assert(N == 8, "!"); } 
  std::array已经有一个名为size的constexpr成员函数,返回你正在查找的值。 
 你可以给Foo一个public static constexpr成员。 
 struct Foo { static constexpr std::size_t bar_size = 8; std::array<int, bar_size> bar; } 
 现在你知道Foo::bar_size的大小,如果Foo有多个相同大小的数组,你可以灵活地将bar_size命名为更具描述性的东西。 
你可以像传统数组一样做:
 sizeof(Foo::bar) / sizeof(Foo::bar[0]) 
使用:
 sizeof(Foo::bar) / sizeof(int) 
你可以使用像:
 sizeof Foo().bar