я пытаюсь получить следующие основные функции для компиляции и работать, как ожидалось:шаблоны функций, частичное применение и аргумент шаблона вычет
int main()
{
auto square = [](int x){ return x*x; };
typedef std::vector<int> Row;
typedef std::vector<Row> Mat;
Mat mat;
auto squareElements = Curry(Map<Row>, square);
Mat squaredMat = Map<Mat>(squareElements, mat);
}
Сейчас мой дополнительный код lõoke так:
#include <algorithm>
#include <functional>
#include <iterator>
#include <vector>
template <typename ContainerOut, typename ContainerIn, typename F>
ContainerOut Map(const F& f, const ContainerIn& xs)
{
ContainerOut ys;
// For performance reason one would use
// ys.reserve(xs.size())
// and std::back_inserter instead of std::inserter
// if ys is a std::vector.
auto it = std::inserter(ys, end(ys));
std::transform(begin(xs), end(xs), it, f);
return ys;
}
template <typename Ret, typename Arg1, typename ...Args>
auto Curry(Ret f(Arg1, Args...), Arg1 arg) -> std::function<Ret(Args...)>
{
return [=](Args ...args) { return f(arg, args...); };
}
и это does not compile.
Любая идея, как заставить компилятор вывести параметры шаблона?
Укажите '' ContainerOut' для Map', при вызове 'Map'. например 'Map>', другие параметры шаблона будут выведены компилятором. –
mnciitbhu
Или вы можете по умолчанию использовать его так же, как 'ContainerIn', с небольшим жонглированием. –
@AlanStokes Даже принуждение 'ContainerOut' к тому же, что и' ContainerIn', используя только 'Container' [подобное] (http://ideone.com/IENKSe), не помогает. –