00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PALUDIS_GUARD_PALUDIS_JOIN_HH
00021 #define PALUDIS_GUARD_PALUDIS_JOIN_HH 1
00022
00023 #include <paludis/util/stringify.hh>
00024 #include <iterator>
00025 #include <string>
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 namespace paludis
00038 {
00039
00040
00041
00042
00043
00044 template <typename I_, typename T_>
00045 T_ join(I_ i, I_ end, const T_ & joiner)
00046 {
00047 T_ result;
00048 if (i != end)
00049 while (true)
00050 {
00051 result += stringify(*i);
00052 if (++i == end)
00053 break;
00054 result += joiner;
00055 }
00056 return result;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 template <typename I_, typename T_, typename F_>
00066 T_ join(I_ i, I_ end, const T_ & joiner, const F_ & f)
00067 {
00068 T_ result;
00069 if (i != end)
00070 while (true)
00071 {
00072 result += (f)(*i);
00073 if (++i == end)
00074 break;
00075 result += joiner;
00076 }
00077 return result;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 template <typename I_>
00087 std::string join(I_ begin, const I_ end, const char * const t)
00088 {
00089 return join(begin, end, std::string(t));
00090 }
00091
00092
00093
00094
00095
00096
00097
00098 template <typename I_, typename F_>
00099 std::string join(I_ begin, const I_ end, const char * const t, const F_ & f)
00100 {
00101 return join(begin, end, std::string(t), f);
00102 }
00103 }
00104
00105 #endif