Как работать с шаблоном, который является параметром шаблона - PullRequest
2 голосов
/ 14 июня 2019

Я пытаюсь составить двойной список какого-то типа.В данном случае это двойной список «BoardCell».Вот моя реализация для 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;
};

А вот реализация для BoardCell: (когда "CellType" и "Direction" являются перечислениями)

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

теперь я пытаюсь сделатьGameBoard.Это моя попытка, и я не могу найти, почему она не работает:

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;
};

(Да, это вложенный шаблон x3 :() Я считаю, что строка шаблона хороша, а typedefпроблема в плате.

Правка - ДОБАВЛЕНИЕ: Вот пример для ввода GameBoard:

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​;

Я не использую std :: tuple, потому что это часть Домашней работы инам нужно реализовать также список.

1 Ответ

1 голос
/ 14 июня 2019

BoardCell в GameBoard совершенно не относится к шаблону BoardCell, то же самое относится к two List s.

Ничего подобного вы не определили

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

, с помощью которого вы можете перейти к определению GameBoard. Скорее всего, вам следует передать конкретную вашего шаблона List, например

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​>>>

Но тогда у вас есть определение бездействия

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