Я хочу, чтобы реализовать шаблон класса, который:станд :: кортеж станд :: shared_ptr параметра шаблона пакета
- ведет себя как функция
- это входные и выходные переменные все совместно.
- относительно прост в использовании.
В результате, я строю следующее:
// all input/output variable's base class
class basic_logic_parameter;
// input/output variable, has theire value and iterators to functions that reference to this variable
template <typename FuncIterator, typename ValueType>
class logic_parameter
:public basic_logic_parameter
{
private:
std::list<FuncIterator> _refedFuncs;
ValueType _val;
public:
};
// all `function`'s base class
class basic_logic_function
{
public:
virtual ~basic_logic_function() = 0;
};
// the function, has input/output variable
template <typename FuncIterator, typename R, typename... Args>
class logic_function_base
:public basic_logic_function
{
private:
std::shared_ptr<logic_parameter<FuncIterator, R>> _ret;
std::tuple<std::shared_ptr<logic_parameter<FuncIterator, Args>>...> _args;
public:
template <std::size_t N>
decltype(auto) arg()
{
return std::get<N>(_args);
}
template <std::size_t N>
struct arg_type
{
typedef std::tuple_element_t<N> type;
};
template <std::size_t N>
using arg_type_t = arg_type<N>::type;
decltype(auto) ret()
{
return _ret;
}
};
Я хотел бы использовать, поскольку они, как:
// drawing need color and a pen
struct Color
{
};
struct Pen
{
};
struct Iter
{
};
class Drawer
:public logic_function_base<Iter, void(Color, Pen)>
{
public:
void draw()
{
arg_type_t<0> pColor; // wrong
}
}
Мой компилятор не может передать этот код через, почему? Я просто хочу преобразовать параметр шаблона пакета в std::tuple of std::shared_ptr of them.
, например:
Учитывая struct A, int, struct C
, я хочу иметь:
std::tuple<
std::shared_ptr<logic_parameter<A>>,
std::shared_ptr<logic_parameter<int>>,
std::shared_ptr<logic_parameter<C>>,
>
Там очевидные ошибки в коде (отсутствующий 'кортеж 'для' std :: tuple_element_t' или отсутствует 'typename'), являются ли эти ошибки копирования/вставки? – Holt
'R (Args ...)' не магически расширен в 'typename R, typename ... Args' самостоятельно, perpahs [использовать частичную специализацию и исправить пару ошибок] (http: //coliru.stacked -crooked.com/a/e9c5cd84502ef962) –
@Holt это ошибка ввода :) – ChungkingExpress