数组大小元函数 - 是在boost某处? [英] Array size metafunction - is it in boost somewhere?

查看:122
本文介绍了数组大小元函数 - 是在boost某处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在博客上找到了以下模板:

I found the following template on a blog:

template <typename T, size_t N>
struct array_info<T[N]>
{
    typedef T type;
    enum { size = N };
};

这是一个优雅的替代 sizeof(a)/ sizeof 0])

用于获取数组大小的常用构造应该是库中的某个位置。我不知道一个。任何人都可以告诉我这个功能是在标准库中和/或在Boost?

A commonly-used construct for getting the size of an array should surely be somewhere in a library. I'm not aware of one. Can anyone tell me this functionality is in the standard libraries somewhere and/or in Boost? Preferably in an easy-to-use and lightweight form.

推荐答案

我最终自己找到了答案 - boost :: size()

I eventually found the answer myself - boost::size():

#include <boost/range.hpp>

int array[10];
boost::size(array); // returns 10

这篇关于数组大小元函数 - 是在boost某处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆