Commit 5bdec549ec5c66f512b266d49b510f53b798e64c

Authored by Jordi Inglada
2 parents 28be289b d61fb443
Exists in master

Merge branch 'master' of http://tully.ups-tlse.fr/jordi/cbutils

Showing 1 changed file with 20 additions and 0 deletions   Show diff stats
include/cbutils.h
... ... @@ -40,6 +40,17 @@ std::vector<std::string> split(const std::string& str,
40 40 boost::token_compress_on);
41 41 return tokens;
42 42 }
  43 +// Joins a vector of strings into a string
  44 +std::string join(const std::vector<std::string>& vos, char sep=' ')
  45 +{
  46 + std::stringstream ss;
  47 + ss << vos[0];
  48 + for(size_t i=1; i<vos.size(); ++i)
  49 + {
  50 + ss << sep << vos[i];
  51 + }
  52 + return ss.str();
  53 +}
43 54 } //end ns string
44 55 // ----------------- System calls ----------------------------------------------
45 56 namespace system{
... ... @@ -103,6 +114,15 @@ Seq tail(const Seq&amp; s)
103 114 std::copy(head, std::end(s), std::back_inserter(result));
104 115 return result;
105 116 }
  117 +//Returns the last element of a sequence
  118 +template <typename Seq>
  119 +auto last(const Seq& s)
  120 +{
  121 + auto element = s.cend();
  122 + --element;
  123 + return *element;
  124 +}
  125 +//python-like range function
106 126 template <typename T>
107 127 std::vector<T> range(T minvalue, T maxvalue, T step=1)
108 128 {
... ...