CPP авто при ошибке кортежа: нельзя ссылаться - это удаленная функция - PullRequest
0 голосов
/ 06 мая 2020

Я работаю с кортежами и авто, и я столкнулся со следующими ошибками. Что я делаю не так?

#include <iostream>
#include <string>
#include <tuple>

struct Custom
{
    enum {INT, STRING} tags;
    union dummy {
        std::string s;
        uint64_t i;
    };
};

int main()
{
    std::tuple<std::string, uint64_t> xs = {"hello World", 45};
    auto [str, i] = xs;
    std::cout<<str<<" "<<i<<"\n"; // works fine

    Custom c1 = {Custom::INT, 45}; // error: too many initializers for 'Custom'

    std::tuple<std::string, Custom> xs1 = {"hello World", { Custom::Tag::INT ,45}}; // error: too many initializers for 'Custom'
    auto [p1, p2] = xs1; // error: cannot be referenced -- it is a deleted function
}
...