When declaring a char array in structure, a compile error occurs at a certain size In Boost 1.84 Requires C++20.
#include <iostream>
#include <string>
#include <boost/pfr.hpp>
#include <boost/pfr/core.hpp>
#include <boost/pfr/core_name.hpp>
#include <boost/type_index.hpp>
struct Foo
{
//std::string attr01; // Compile OK
//std::string attr02; // Compile OK
//std::string attr03; // Compile 0K
char attr01[600]; // Compile Error
//char attr02[100];
//char attr03[200];
//char attr04[600];
//char attr05[600];
//char attr06[600];
//char attr07[600];
//char attr08[600];
//char attr09[600];
//char attr10[600];
//char attr11[600];
//char attr12[600];
//char attr13[600];
//char attr14[600];
//char attr15[600];
//char attr16[600];
//char attr17[600];
//char attr18[600];
//char attr19[600];
//char attr20[600];
};
int main() {
Foo foo;
auto names = boost::pfr::names_as_array<Foo>();
boost::pfr::for_each_field(foo, [&names](const auto& field, std::size_t idx) {
std::cout << names[idx] << " : " << boost::typeindex::type_id_runtime(field) << "\n";
});
return 0;
}
OUTPUT compile error occur error : C2672 'boost::pfr::detail::name_of_field': There are no matching overloaded functions.
From the docs:
And
And further down:
Indeed, avoid the C-style arrays. Use
std::arrayinstead. You can force the issue by wrapping in something like a tuple:Live On Coliru
Printing e.g.