message: elle.make_vector: add make_vector_if and make_set
diff: #pragma once
  #include <algorithm>
  +#include <set>
  #include <vector>
  +#include <boost/algorithm/cxx11/copy_if.hpp>
  +#include <boost/range/algorithm/transform.hpp>
  +
  namespace elle
  {
  + /*------.
  + | Set. |
  + `------*/
  +
  + /// A set of the values of `fun(e)` for e in c.
  + ///
  + /// @param c A container to apply the function to.
  + /// @param fun The function to apply.
  + /// @returns A set of images.
  + template <typename Cont, typename Fun>
  + auto
  + make_set(const Cont& c, Fun&& fun)
  + -> std::set<decltype(fun(*c.begin()))> // SFINAE
  + {
  + using Res = decltype(fun(*c.begin()));
  + auto res = std::set<Res>{};
  + boost::transform(c,
  + std::inserter(res, res.end()),
  + std::forward<Fun>(fun));
  + return res;
  + }
  +
  + /// The content of \a cont as a set.
  + ///
  + /// @param c A container.
  + /// @returns A set.
  + template <typename Cont>
  + auto
  + make_set(const Cont& c)
  + -> std::set<typename Cont::value_type>
  + {
  + using std::begin;
  + using std::end;
  + return {begin(c), end(c)};
  + }
  +
  +
  + /*---------.
  + | Vector. |
  + `---------*/
  +
  /// This is really the `map` function in functional languages:
  /// a vector of the values of `fun(e)` for e in c.
  ///
  - /// @param A container to apply the function to.
  - /// @param The function to apply.
  - /// @returns A vector containing the result of the map.
  + /// @param c A container to apply the function to.
  + /// @param fun The function to apply.
  + /// @returns A set containing the result of the map.
  template <typename Cont, typename Fun>
  auto
  make_vector(const Cont& c, Fun&& fun)
  @@ -19,7 +64,7 @@ namespace elle
  using Res = decltype(fun(*c.begin()));
  auto res = std::vector<Res>{};
  res.reserve(c.size());
  - std::transform(c.begin(), c.end(),
  + boost::transform(c,
  std::back_inserter(res),
  std::forward<Fun>(fun));
  return res;
  @@ -27,8 +72,8 @@ namespace elle
  /// The content of \a cont as a vector.
  ///
  - /// @param A container.
  - /// @results A vector.
  + /// @param c A container.
  + /// @returns A set.
  template <typename Cont>
  auto
  make_vector(const Cont& c)
  @@ -38,4 +83,21 @@ namespace elle
  using std::end;
  return {begin(c), end(c)};
  }
  +
  + /// This is really the `filter` function in functional languages:
  + /// a vector of the values of `c` that validate `pred`.
  + ///
  + /// @param c A container to apply the function to.
  + /// @param pred A predicate.
  + /// @returns A set containing the result of the map.
  + template <typename Cont, typename Pred>
  + auto
  + make_vector_if(const Cont& c, Pred&& pred)
  + {
  + auto res = std::vector<typename Cont::value_type>{};
  + boost::algorithm::copy_if(c,
  + std::back_inserter(res),
  + std::forward<Pred>(pred));
  + return res;
  + }
  }
  