A limitation in c++17 mode
- 主要言語
- C++
- スター
- 1.5k
- フォーク
- 176
- 平均マージ
- 5日 21時間
- マージ済み PR(30日)
- 1
説明
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.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
評価
この issue はまだ評価されていません。