c++11 - operate on c++ 11 variadic template parameters, store into tuple -
i'm trying learn bit of c++ 11 variadic template arguments.
i want take list of floating point input arguments converttest(), return std::tuple of ints. try compile following in g++:
template<typename ...argsin, typename ...argsout> static inline std::tuple<argsout...> converttest(float nextarg, argsin... remainingargs) { auto = converttest(remainingargs...); auto b = std::make_tuple(int(nextarg)); auto c = std::tuple_cat(a, b); return c; } static inline std::tuple<int> converttest(float lastargin) { return std::make_tuple((int)lastargin); } int main() { auto res = converttest(0.5f, 10.11f); return 0; }
i following error:
error: conversion 'std::tuple<int, int>' non-scalar type 'std::tuple<>' requested
i'm not sure why return type std::tuple<argsout...>
resolve std::tuple<>
. ideas?
i've tried making return type auto
, complaints missing trailing return types in case.
any ideas?
argout
are non deducible, become empty list. have write function in order instead
template<typename ... argsout, typename ...argsin> static std::tuple<argsout...> converttest(float nextarg, argsin... remainingargs);
and call it
converttest<int, int>(0.5f, 10.11f);
btw, may write (removing fact take exclusively float
)
template<typename ...args> auto converttest(args... args) -> decltype(std::make_tuple(static_cast<int>(args)...)) { return std::make_tuple(static_cast<int>(args)...) }
Comments
Post a Comment