mercredi 28 novembre 2018

c++ add data to a std::vector containing a std::tuple

Below is code that adds elements to a vector containing a std::pair

std::vector<std::pair<std::string, std::type_index>> args_;

template <class T>
            inline OperationEntry& setArg(const std::string& name)
            {
                args_.push_back({name, typeid(T)});
                return *this;

            }

How do I add elements to a vector containing a std::tuple?

std::vector<std::tuple<std::string, std::type_index, Attribute>> args_;

template <class T>
            inline OperationEntry& setArg(const std::string& name, Attribute value = Attribute())
            {
                args_.push_back({name, typeid(T), value});
                return *this;

            }

I tried args_.push_back(std::make_tuple(name, typeid(T), value));

I am getting this error:

[GCC] converting to
‘std::vector<std::tuple<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::type_index,
mv::Attribute> >::value_type {aka
std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::type_index, mv::Attribute>}’ from
initializer list would use explicit constructor ‘constexpr std::tuple<
<template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements =
{const std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >&, const std::type_info&, mv::Attribute&};
<template-parameter-2-2> = void; _Elements =
{std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::type_index, mv::Attribute}]’

Aucun commentaire:

Enregistrer un commentaire