Код: Выделить всё
std::vector v1{1,2,3};
std::vector v2{1.1,2.2,3.3};
std::vector v3{Object{},Object{},Object{}};
Код: Выделить всё
auto v1 = make_vector(1,2,3);
auto v2 = make_vector(1.1,2.2,3.3);
auto v3 = make_vector(Object{},Object{},Object{});
Код: Выделить всё
#include
#include
#include
template
auto make_vector(T&&... args)
{
using first_type = typename std::tuple_element::type;
return std::vector{std::forward(args)...};
}
Код: Выделить всё
auto vec = make_vector(1,2,3);
Код: Выделить всё
m.cpp: In instantiation of ‘auto make_vector(T&& ...) [with T = {int, int, int}]’:
m.cpp:16:30: required from here
m.cpp:8:78: error: invalid use of incomplete type ‘class std::tuple_element’
using first_type = typename std::tuple_element::type;
^
In file included from m.cpp:3:0:
/usr/include/c++/5/utility:85:11: note: declaration of ‘class std::tuple_element’
class tuple_element;
^
m.cpp:9:60: error: invalid use of incomplete type ‘class std::tuple_element’
return std::vector{std::forward(args)...};
^
In file included from m.cpp:3:0:
/usr/include/c++/5/utility:85:11: note: declaration of ‘class std::tuple_element’
class tuple_element;
^
m.cpp: In function ‘int main()’:
m.cpp:16:30: error: ‘void v1’ has incomplete type
auto v1 = make_vector(1,2,3);
которая использует первый тип первого параметра для создания экземпляра вектора?
Как я могу переслать аргументы в качестве значений инициализатора в вектор?
Подробнее здесь: https://stackoverflow.com/questions/369 ... make-tuple
Мобильная версия