简体   繁体   中英

Boost hana size of tuple type

I know how I can obtain the size of an tuple object in boost::hana like this:

auto tupleSize = hana::size(hana::make_tuple(1,2,3))

But what about the size of a tuple type? The stl provides allready the following tuple type trait:

constexpr size_t tupleSize = std::tuple_size<std::tuple<int, int, int>>::value;

Is there a similar type trait within hana?

There is none. My guess is that you are misusing Hana here, or that there's an equivalent way to do what you're trying to achieve without having to call size on a tuple type. But I can't know for sure without seeing the rest of your code, so take this with a grain of salt.

The way you could workaround the lack of a tuple_size -like metafunction is by using declval . You could write:

constexpr size_t tupleSize = decltype(
    hana::size(std::declval<hana::tuple<T...>>())
)::value;

Note that depending on the context in which you have to call this, it might even be possible to use sizeof...(T) if you have this information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM