boostorg / boostorg/pfr

A limitation in c++17 mode

Aperta
#76 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C++
Stelle
1.5k
Fork
176
Merge medio
5g 21h
PR unite (30g)
1

Descrizione

Hi, I thought of using the magic of this library as a shortcut for providing a standard "tuple-like" interface for aggregates, for use in generic code that expects it, in the following way
```c++
#include
#include
#include

namespace ma
{

struct A
{
int a, b;
};
using boost::pfr::get;

}

template <> struct std::tuple_size :
boost::pfr::tuple_size {};
template struct std::tuple_element :
boost::pfr::tuple_element {};

int main()
{
ma::A x{1,2};
using std::get;
std::cout << get<1>(x) << '\n';
}

```
but in c++17 mode this creates a sort of a circular dependency. As far as I understand, the pfr::get (along with pfr::tuple_element) depends on structured binding, which (since std::tuple_size is specialized) depends on ADLed get, which is the pfr::get again. The whole thing manifests as a compiler error like this on gcc 10.2
```
In file included from ./pfr/include/boost/pfr.hpp:12,
from boost_pfr.cpp:1:
./pfr/include/boost/pfr/core.hpp: In instantiation of ‘constexpr decltype(auto) boost::pfr::get(T&) [with long unsigned int I = 0; T = ma::A]’:
./pfr/include/boost/pfr/detail/core17_generated.hpp:51:10: required from ‘constexpr auto boost::pfr::detail::tie_as_tuple(T&, boost::pfr::detail::size_t_<2>) [with T = ma::A; boost::pfr::detail::size_t_<2> = std::integral_constant]’
./pfr/include/boost/pfr/detail/core17.hpp:55:42: required from ‘constexpr auto boost::pfr::detail::tie_as_tuple(T&) [with T = ma::A]’
./pfr/include/boost/pfr/core.hpp:81:108: required by substitution of ‘template using tuple_element = boost::pfr::detail::sequence_tuple::tuple_element()))> [with long unsigned int I = i; T = ma::A]’
boost_pfr.cpp:19:36: required from here
./pfr/include/boost/pfr/core.hpp:54:64: error: use of ‘constexpr auto boost::pfr::detail::tie_as_tuple(T&) [with T = ma::A]’ before deduction of ‘auto’
54 | return detail::sequence_tuple::get( detail::tie_as_tuple(val) );
| ~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from ./pfr/include/boost/pfr/detail/core17.hpp:10,
from ./pfr/include/boost/pfr/detail/core.hpp:17,
from ./pfr/include/boost/pfr/core.hpp:12,
from ./pfr/include/boost/pfr.hpp:12,
from boost_pfr.cpp:1:
./pfr/include/boost/pfr/detail/core17_generated.hpp: In instantiation of ‘constexpr auto boost::pfr::detail::tie_as_tuple(T&, boost::pfr::detail::size_t_<2>) [with T = ma::A; boost::pfr::detail::size_t_<2> = std::integral_constant]’:
./pfr/include/boost/pfr/detail/core17.hpp:55:42: required from ‘constexpr auto boost::pfr::detail::tie_as_tuple(T&) [with T = ma::A]’
./pfr/include/boost/pfr/core.hpp:81:108: required by substitution of ‘template using tuple_element = boost::pfr::detail::sequence_tuple::tuple_element()))> [with long unsigned int I = i; T = ma::A]’
boost_pfr.cpp:19:36: required from here
./pfr/include/boost/pfr/detail/core17_generated.hpp:51:10: note: in initialization of structured binding variable ‘a’
51 | auto& [a,b] = val; // ====================> Boost.PFR: User-provided type is not a SimpleAggregate.
| ^
```

I guess this kind of usage is somewhat out of scope of the library, but it seems to work fine with BOOST_PFR_USE_CPP17 defined as 0.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.