文档提到:
template gen_type<Ranges>::type
- 此类型生成器用于指定对 的
Ranges
链式调用的结果extent_gen::operator[]
。
wheregen_type
是boost::multi_array_types::extent_gen
(boost::multi_array_types::extent_gen
也是全局辅助对象的类型boost::extents
)的成员。
您还可以看到以这种方式指定了接受一组范围的构造函数(至少出于公共文档的目的)。 例如,
namespace boost {
template <typename ValueType,
std::size_t NumDims,
typename Allocator = std::allocator<ValueType> >
class multi_array {
...
typedef multi_array_types::extent_gen extent_gen;
...
explicit multi_array(extent_gen::gen_type<NumDims>::type ranges,
const storage_order_type& store = c_storage_order(),
const Allocator& alloc = Allocator());
auto
因此,您可以在不使用as的情况下重写该行代码:
boost::multi_array_types::extent_gen::gen_type<3>::type my_shape =
boost::extents[3][4][5];
这对于局部变量来说有点傻,但也许你想在一个类或类似的东西中存储一组范围。如果是这样,这就是根据官方文档接口的方法。
(如注释中所述,此 typedef 解析为的实际类型涉及boost::internal::
,但您不应在代码中使用“内部”命名空间中的任何内容,因为这可能会在未来版本中发生变化。)