pfr icon indicating copy to clipboard operation
pfr copied to clipboard

names_as_array returns an incorrect type when the input has zero fields

Open anarthal opened this issue 1 year ago • 1 comments

Compiler: gcc13.1, Linux Boost 1.84 Godbolt: https://godbolt.org/z/xxT1Tsoe7 Description: when names_as_array is called on a struct with no fields, std::array<std::nullptr_t, N> is returned, rather than std::array<std::string_view, 0>. This makes generic code more difficult.

#include <boost/pfr.hpp>

namespace pfr = boost::pfr;

struct MyType {};

int main()
{
    std::array<std::string_view, 0> names = pfr::names_as_array<MyType>(); 
}

anarthal avatar Mar 21 '24 18:03 anarthal

Happens on clang-19 (on my machine) too.

anarthal avatar Mar 21 '24 18:03 anarthal