template return type

closed account (SECMoG1T)
Hi, i need help here , av gotta snippet here and i need to identify what causes the error.

1
2
3
4
5
6
7
8
template<typename T>
using ret_tuple=std::tuple<std::vector<std::size_t>,std::vector<std::string>,std::vector<T>>;

template<typename ... CONT,typename T>
ret_tuple my_collection(const CONT&&... conts<T>)///error on return type
{
 ///.... code here
}


the error occur on the return type of my function {my_collection} i need to know how i can make ret_tuple use the template parameter T from this function

error! invalid use of template name ret_tuple without arg list



Error	2	error C3547: template parameter 'T' cannot be used because it follows a
 template parameter pack and cannot be deduced from the function parameters of 
'my_collection'	c:\users\orion\documents\visual studio 2013\projects\azure\azure.cpp	11	1	Azure



is it possible to pass T the template param from this function to ret_tuple?? i tried this ret_tuple<T> it failed with some other errors.

thanks in advance.
Last edited on
I think you have placed the <T> in the wrong place. You need it at the return type instead of the parameter.
1
2
3
4
5
template<typename ... CONT,typename T>
ret_tuple<T> my_collection(const CONT&&... conts)
{
 ///.... code here
}
closed account (SECMoG1T)
Thank you @Peter but i also need to specialize conts to be of type T only
they are containers
is it possible? thanks man.
closed account (SECMoG1T)
#updated


Well this compiles but i need conts to be of type T is it possible
1
2
3
4
5
6
7
8
9
10
11
12

template<typename T>
using ret_tuple =std::tuple<std::vector<std::size_t>,std::vector<std::string>,std::vector<T>>;

template<typename T,typename... CONT>
ret_tuple<T> my_collection(const CONT&&... conts)
{
  ///code  here
}


Last edited on
closed account (SECMoG1T)
Anyone please.
Maybe you can use std::enable_if or something like that to enforce the types are correct, but for the time being you can just assume the types passed to the function are correct. What you should be worrying about instead is how to extract the containers from conts.

If you are not going to pass the whole template parameter pack (conts) to another function you will have to let the first container be its own parameter and then call the function recursively. You probably also need to create a my_collection version that takes less arguments to stop the recursion. Take a look at the definition of "func()" at http://en.wikipedia.org/wiki/Variadic_template
closed account (SECMoG1T)
ooh thanks n yea av got yet another function evaluate but i could proceed with the error, maybe i'll just limit my usage to single integral types

Thank you man.
Topic archived. No new replies allowed.