Confusion while deriving from std::tuple, can not handle std::get

孤人 提交于 2019-12-05 04:08:04
PiotrNycz

Unfortunately you have to add your container versions of get functions:

template <std::size_t I, typename ...T>
decltype(auto) get(TypeContainer<T...>&& v)
{
    return std::get<I>(static_cast<std::tuple<T...>&&>(v));
}
template <std::size_t I, typename ...T>
decltype(auto) get(TypeContainer<T...>& v)
{
    return std::get<I>(static_cast<std::tuple<T...>&>(v));
}
template <std::size_t I, typename ...T>
decltype(auto) get(TypeContainer<T...> const& v)
{
    return std::get<I>(static_cast<std::tuple<T...> const&>(v));
}

And just use get not std::get in Do kind of functions. Compiler is able to select namespace from arguments.

I guess, I am not sure, that this is because gcc has EBO - Empty Base Optimization - implemented in its tuples. What are exact reason it is quite hard to guess. You might consider to report this in gcc bugzilla.


BTW, it is not good habit to derive from STD classes. If you started from compisition, not inheritance, then you would need to provide your own get functions and you would not observe this error, saving probably a lot of time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!