How to remove last arg in vardiadic template

Hi!

I wonder if it is possible to remove the last argument in an argument pack?
Below is an example on what I want to accomplish:
1
2
3
4
5
6
7
8
9
template<template<int...> class A,int... Ints>
A<remove_last_int<Ints...>::list> func(const A<Ints...> & a0)
{
    A<remove_last_int<Ints...>::list> a;
    ...
    //Here a set the members of a based on a0.
    ...
    return a;
}

For example, I want the return a A<1,2> value from (const A<1,2,3> & a0)
What do you want to happen if there is one argument? If there are no arguments?
With one argument I simply want to return an empty A<> and I don't want it to compile if Ints... is empty.

I have tried something in line with

http://stackoverflow.com/questions/16268107/attempt-to-remove-last-type-from-a-tuple-is-failing

But where I want to use a non-type template class. But I can't get this to work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    template<template<int... Is> class A,int... Is>
    struct rmli;

    template<template<int I> class A,int I>
    struct rmli<A<I>,I>
    {
        using type = A<>;
    };

    template <template<int I,int... Is> class A, int I,int... Is>
    struct rmli<A<I,Is>,I,Is>
    {
        using type = typename concat<A<I>,I,typename rmli<A<Is...>,Is...>::type>::type;
    };

    template<template<int I1> class A,int I1,template<int I2> class A,int I2>
    struct concat{ };

    template<template<int... Is1> class A,int... Is1,template<int... Is2> class A, int... Is2>
    struct concat<A<Is1...>,Is1...,A<Is2...>,Is2...>
    {
        using type = A<Is1...,Is2...>;
    };


And the compiler sais, among other things that


error: type/value mismatch at argument 1 in template parameter list for 'template<template<int ...Is> class A, int ...Is> struct rmli'
error:   expected a class template, got 'A<I>'


Any ideas how to get it to work? I know some things look a bit silly, but I just tried to copy what the link above said so that you can get an idea of what I want to do.
Last edited on
Why do you have a template inside a template? That doesn't make sense and I don't see it anywhere on that SO QA.

EDIT: I should have noticed it in your first post...it still doesn't make sense, where have you seen that syntax? I've never seen it :S
Last edited on
Okay,

I must have mixed things up then, but it seems, as for example in this link

http://stackoverflow.com/questions/14537090/c-using-nested-template-classes-for-carrying-type-information

that you can use nested templates

1
2
3
4
5
template<template<class T> class Container, class Obj>
struct Type
{
  typedef typename Container<Obj>::type type;
};
And for me it seems very reasonable that you would like to specify that your class template can take template arguments. Is that not possible you say?
Either I am doing something wrong and this is syntax I have never seen before, or that code is just invalid:
http://ideone.com/vbMkDu
I guess you are right, and when thinking about it, it seems really hard to make sense of it. So thanks for you insight!
Hey! I solved it, and here is the solution if you are interested:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    //Strip last int in tensor type
    template <int... I>
    struct strip;

    template <int I>
    struct strip<I>
    {
        using type = Tensor<>;
    };

    template<typename,typename>
    struct concat { };

    template<int... Is1,int... Is2>
    struct concat<Tensor<Is1...>,Tensor<Is2...>>
    {
        using type = Tensor<Is1..., Is2...>;
    };

    template <int I,int... Is>
    struct strip<I,Is...>
    {
        using type = typename concat<Tensor<I>, typename strip<Is...>::type>::type;
    };


What I was looking for was this solution but where "tensor" can be any type taking int... as its template argument. Not just template<int...> struct tensor.
Topic archived. No new replies allowed.