简体   繁体   中英

Using std::tuple_size on classes derived from std::array

I have code that kinda looks like the following:

#include <array>

class DoubleArray: std::array<double, 16> {
public:
    void clear() {
        fill(0.0);
    }
};

Now I would like to use the size of the std::array as a compile time constant. If DoubleArray was just a typedef to std::array I could use std::tuple_size<DoubleArray>::value but using inheritance instead I get the following compiler error:

error: incomplete type ‘std::tuple_size<DoubleArray>’ used in nested name specifier

I have seen tuple_size and an inhereted class from tuple? but since that only talks about std::tuple I don't think it can be applied. Any ideas why this doesn't work and if there is an easy way to make it work?

Just call size() - for arrays it is a constexpr .

See here: http://en.cppreference.com/w/cpp/container/array/size or check § 23.3.2.1.3 where it is defined as constexpr size_type size() noexcept;

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