19 #ifndef ROSTLAB_AUX_FUNTIONS
20 #define ROSTLAB_AUX_FUNTIONS 1
29 template<
typename _Tp>
30 inline std::basic_string<_Tp>
31 join(
const std::basic_string<_Tp>& __sep,
typename std::vector< std::basic_string<_Tp> >::const_iterator __begin,
typename std::vector< std::basic_string<_Tp> >::const_iterator __end )
33 std::basic_string<_Tp> buf;
34 for(
typename std::vector< std::basic_string<_Tp> >::const_iterator v_i = __begin; v_i != __end; ++v_i )
36 if( buf.size() ) buf += __sep; buf += *v_i;
42 template<
typename _Tp>
43 inline std::basic_string<_Tp>
44 join(
const std::basic_string<_Tp>& __sep,
const std::vector< std::basic_string<_Tp> >& __v )
46 return join( __sep, __v.begin(), __v.end() );
50 template<
typename _Tp>
51 inline std::basic_string<_Tp>
52 join(
const _Tp* __sep,
const std::vector< std::basic_string<_Tp> >& __v )
54 return join( std::string(__sep), __v );
58 template<
typename _Tp>
59 inline std::basic_string<_Tp>
60 join(
const _Tp __sep,
const std::vector< std::basic_string<_Tp> >& __v )
62 return join( std::string( 1, __sep ), __v );
66 inline std::vector<std::string>
67 split(
const std::string& __str,
char __c )
69 std::vector<std::string> ret;
70 if( __str.empty() )
return ret;
71 std::string::size_type pos = 0;
72 do { std::string::size_type new_pos = __str.find( __c, pos ); ret.push_back( new_pos != std::string::npos ? __str.substr( pos, new_pos-pos ) : __str.substr( pos ) ); pos = new_pos;
if( pos != std::string::npos ) ++pos; }
while( pos != std::string::npos );
77 template<
typename _Tk,
typename _Tv>
78 inline std::vector<_Tk>
82 ret.reserve( __map.size() );
83 for(
typename std::map<_Tk, _Tv>::const_iterator m_i = __map.begin(); m_i != __map.end(); ++m_i ) ret.push_back( m_i->first );
88 inline void split_in_2(
const std::string& __str,
char __c, std::string& __left, std::string& __right )
90 std::string::size_type pos = __str.find( __c );
91 if( pos == std::string::npos )
97 __left = __str.substr( 0, pos );
98 __right = __str.substr( pos+1 );
103 inline std::map<std::string, std::string>
106 std::map<std::string, std::string> ret;
107 for( std::vector<std::string>::const_iterator s_i = __svec.begin(); s_i != __svec.end(); ++s_i )
109 std::string left, right;
153 template<
class _T1,
class _T2>
155 std::ostream &
operator<< (std::ostream &os,
const std::pair<_T1, _T2>& v)
157 os << v.first <<
" => " << v.second;
163 template<
typename K,
typename V,
class C,
class A>
165 std::ostream&
operator<< (std::ostream &os,
const std::map<K,V,C,A>& m)
168 for(
typename std::map<K,V,C,A>::const_iterator p = m.begin(), p_end = m.end(); p != p_end; ++p )
170 if( p != m.begin() ) os <<
", ";
179 template<
typename _Tp,
typename _Alloc>
181 std::ostream &
operator<< (std::ostream &os,
const std::vector<_Tp, _Alloc>& v)
183 typename std::vector<_Tp, _Alloc>::const_iterator v_i;
185 for( v_i = v.begin(); v_i != v.end(); ++v_i )
186 {
if( v_i != v.begin() ) os <<
", "; os << *v_i; }
194 #endif // ROSTLAB_AUX_FUNTIONS