Mercurial > code
comparison cpp/join/join.hpp @ 648:5bd9424a523a
misc: extreme cleanup
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 04 Oct 2018 21:17:55 +0200 |
parents | 89c1d2bd33eb |
children | 87e1f4c7da76 |
comparison
equal
deleted
inserted
replaced
647:0557eea4d373 | 648:5bd9424a523a |
---|---|
34 * \return the string | 34 * \return the string |
35 */ | 35 */ |
36 template <typename InputIt, typename DelimType = char> | 36 template <typename InputIt, typename DelimType = char> |
37 auto join(InputIt first, InputIt last, DelimType delim = ':') -> std::string | 37 auto join(InputIt first, InputIt last, DelimType delim = ':') -> std::string |
38 { | 38 { |
39 std::ostringstream oss; | 39 std::ostringstream oss; |
40 | 40 |
41 if (first != last) { | 41 if (first != last) { |
42 oss << *first; | 42 oss << *first; |
43 | 43 |
44 while (++first != last) | 44 while (++first != last) |
45 oss << delim << *first; | 45 oss << delim << *first; |
46 } | 46 } |
47 | 47 |
48 return oss.str(); | 48 return oss.str(); |
49 } | 49 } |
50 | 50 |
51 /** | 51 /** |
52 * Convenient overload. | 52 * Convenient overload. |
53 * | 53 * |
56 * \return the string | 56 * \return the string |
57 */ | 57 */ |
58 template <typename T, typename DelimType = char> | 58 template <typename T, typename DelimType = char> |
59 auto join(std::initializer_list<T> list, DelimType delim = ':') -> std::string | 59 auto join(std::initializer_list<T> list, DelimType delim = ':') -> std::string |
60 { | 60 { |
61 return join(list.begin(), list.end(), delim); | 61 return join(list.begin(), list.end(), delim); |
62 } | 62 } |