1

I have a class A that is non default initializable that I can't modify.

How can I create a length zero std::array containing said class?

This works in both clang and gcc but not MSVC.

#include <array>

struct A {
    A(double, int) {};
};

using Empty = std::array<A, 0>;

inline const Empty GetChildren() {
    return {};
};

int main(int argc, char **argv) {
    const Empty& test(GetChildren());
    for (const auto& a : GetChildren()) {}
} 
Bomaz
  • 1,871
  • 1
  • 17
  • 22
  • 3
    What's the point of creating a const empty array? – DimChtz Apr 23 '18 at 21:50
  • 2
    Could you please specify how it does not work? Do you have an error message? – BobMorane Apr 23 '18 at 21:53
  • 2
    According to https://stackoverflow.com/a/44815242, this is supposed to work, and the fact that MSVC doesn't compile it is either a bug in the standard for not being clear enough in allowing it, or a bug in MSVC. It means any answer you'll get will be a workaround that involves not actually using `std::array`. –  Apr 23 '18 at 21:53

0 Answers0