idan
idan

Reputation: 23

How to work with template which are template parameter

I'm trying to make a double list of some type. In this case it is double list of "BoardCell". Here is my implementation for List:

template<typename T, typename... TT>
struct List {
    typedef T head;
    typedef List<TT...> next;
    constexpr static int size = 1 + next::size;
};

template<typename T>
struct List<T> {
    typedef T head;
    constexpr static int size = 1;
};

And here is the implementation for BoardCell:(when "CellType" and "Direction" are enums)

template<CellType CT, Direction D, int L>
struct BoardCell {
    constexpr static CellType type = CT;
    constexpr static Direction direction = D;
    constexpr static int length = L;
};

now im trying to make the GameBoard. This is my trying, and I cant find why it is not working:

template<template<template<template<CellType C, Direction D, int L> class BoardCell> class List> class List>
struct GameBoard {
    typedef List<List<BoardCell<C, D, L>>> board;
};

(Yes, this is x3 nested template :( ) I believe the line of the template is good, and the typedef of the board is the problem in here.

Edit- ADDITION: Here is an example for GameBoard input:

typedef​ ​GameBoard​<​List​<​ ​List​<​ ​BoardCell​<​EMPTY​,​ UP​,​ ​0​>,​ ​BoardCell​<​EMPTY​,​ UP​,​ ​0​>>,
                        List​<​ ​BoardCell​<​X​,​ RIGHT​,​ ​1​>,​ ​BoardCell​<​A​,​ UP​,​ ​1​>>,
                        List​<​ ​BoardCell​<​EMPTY​,​ UP​,​ ​0​>,​ ​BoardCell​<​EMPTY​,​ UP​,​ ​0​>>>>​ gameBoard​;

I do not use std::tuple because this is a part of Homework and we need to implement also the list.

Upvotes: 2

Views: 67

Answers (1)

Caleth
Caleth

Reputation: 63152

BoardCell in GameBoard is entirely unrelated to the BoardCell template, ditto the two Lists.

There isn't anything you have defined of kind

template<template<template<CellType, Direction, int> class> class> class

with which you can pass to your definition of GameBoard. Most likely, you should be passing a specific instantiation of your List template, such as

List​<​ ​List​<​ ​BoardCell​<​EMPTY​,​ UP​,​ ​0​>,​ ​BoardCell​<​EMPTY​,​ UP​,​ ​0​>>,
      List​<​ ​BoardCell​<​X​,​ RIGHT​,​ ​1​>,​ ​BoardCell​<​A​,​ UP​,​ ​1​>>,
      List​<​ ​BoardCell​<​EMPTY​,​ UP​,​ ​0​>,​ ​BoardCell​<​EMPTY​,​ UP​,​ ​0​>>>

But then you have a do-nothing definition

template<typename Board>
struct GameBoard {
    typedef Board board;
};

Upvotes: 1

Related Questions