Программы на C++. Форум разработчиков
Anonymous
Структурированное объявление связывания для класса, унаследованных от кортежей
Сообщение
Anonymous » 18 фев 2025, 10:10
У меня есть класс, унаследованный от стандартного кортежа: < /p>
Код: Выделить всё
#include
#include
#include
#include
#include
#include
template< typename ... Args >
class Identifier: public std::tuple< Args... >
{
public:
Identifier( Args... args ) requires( sizeof...( Args ) != 0 ) : std::tuple< Args... >( std::move( args )... )
{}
Identifier( std::tuple< Args... > tuple ):std::tuple< Args... >( tuple )
{}
Identifier()
{}
Identifier(std::convertible_to auto&& identifier)
: std::tuple(std::forward(identifier)) {}
};
int main()
{
Identifier id(L"id", 10);
auto& [ str_id, num_id ] = id;
std::tuple< std::wstring, int64_t > tuple_id(L"id", 10);
auto& [ str_t_id, num_t_id ] = tuple_id;
return 0;
}
< /code>
в строке < /p>
auto& [ str_id, num_id ] = item;
< /code>
Я получил тип ошибки Предоставлено < /p>
, но тот же код для переменной кортежей это OK < /p>
auto& [ str_t_id, num_t_id ] = tuple_id;
Что я должен сделать, чтобы поддержать структурированное привязку для идентификатора класса?
Подробнее здесь:
https://stackoverflow.com/questions/794 ... from-tuple
1739862621
Anonymous
У меня есть класс, унаследованный от стандартного кортежа: < /p> [code]#include #include #include #include #include #include template< typename ... Args > class Identifier: public std::tuple< Args... > { public: Identifier( Args... args ) requires( sizeof...( Args ) != 0 ) : std::tuple< Args... >( std::move( args )... ) {} Identifier( std::tuple< Args... > tuple ):std::tuple< Args... >( tuple ) {} Identifier() {} Identifier(std::convertible_to auto&& identifier) : std::tuple(std::forward(identifier)) {} }; int main() { Identifier id(L"id", 10); auto& [ str_id, num_id ] = id; std::tuple< std::wstring, int64_t > tuple_id(L"id", 10); auto& [ str_t_id, num_t_id ] = tuple_id; return 0; } < /code> в строке < /p> auto& [ str_id, num_id ] = item; < /code> Я получил тип ошибки Предоставлено < /p> , но тот же код для переменной кортежей это OK < /p> auto& [ str_t_id, num_t_id ] = tuple_id; [/code] Что я должен сделать, чтобы поддержать структурированное привязку для идентификатора класса? Подробнее здесь: [url]https://stackoverflow.com/questions/79446627/structured-binding-declaration-for-class-inherited-from-tuple[/url]