Q: Overloading std::transform algorithm Consider this standard use of std::transform algorithm:
vector<int> in = { 1, 2, 3 };
auto f0 = [](int val) { return val + 1; };
auto f1 = [](int val) { return val > 1; };

vector<int> out0(in.size()); 
std::transform(in.begin(), in.end(), out0.begin(), f0);
vector<bool> out1(in.size()); 
std::transform(in.begin(), in.end(), out1.begin(), f1);

This works fine but is long to write. I would like to write something like this:
auto out0 = tranform(in, f0);
auto out1 = tranform(in, f1);

How to overload the transform algorithm to allow this syntax?

A: The following should do what you want
#include <algorithm>
#include <iostream>
#include <type_traits>
#include <vector>

template<typename T, typename F>
std::vector<typename std::result_of<F(T)>::type>
transform(const std::vector<T>& l, F func)
{
    typedef typename std::result_of<F(T)>::type FunctorReturnType;
    std::vector<FunctorReturnType> out(l.size());
    std::transform(l.begin(), l.end(), out.begin(), func);
    return out;
}

int main ()
{
    const std::vector<int> in{ 1, 2, 3 };
    auto f0 = [](int val) { return val + 1; };
    auto f1 = [](int val) { return val > 1; };

    auto out0 = transform(in, f0);
    auto out1 = transform(in, f1);

    for (const auto& m: out0) std::cout << m << std::endl;
    for (const auto& m: out1) std::cout << m << std::endl;
}


A: Do you like template template arguments? This works with more containers than vectors.
template<template<class...> class C, class F, class T, class... Tail>
C<typename result_of<F(T)>::type>
transform(const C<T, Tail...>& in, F func)
{
    C<typename result_of<F(T)>::type> out(in.size());
    std::transform(in.begin(), in.end(), out.begin(), func);
    return out;
}

Can be seen working at http://coliru.stacked-crooked.com/a/767adb662d7cbe42
EDIT: changed to not use the source's allocator in the resulting container.

A: Why aren't you ok with the following, which doesn't use any C++11 magic such as decltype ? 
#include <algorithm>
#include <vector>
template<class T, class F>
std::vector<T> transform(const std::vector<T>& l, F func)
{
  std::vector<T> out(l.size());
  std::transform(l.begin(), l.end(), out.begin(), func);
  return out;
}

