1 #ifndef _theplu_yat_utility_getvector_ 2 #define _theplu_yat_utility_getvector_ 25 #include <yat/utility/split.h> 28 #include <boost/type_traits/is_same.hpp> 52 std::istream&
getvector(std::istream&
is, std::vector<T>& result,
53 char delim,
char newlinedelim=
'\n');
62 std::istream&
getvector(std::istream&
is, std::vector<T>& result,
63 const std::string& delim,
char newlinedelim=
'\n');
70 void convert(std::vector<std::string>& vec,
71 std::vector<T>& result, boost::true_type is_string)
75 std::swap(vec, result);
80 void convert(std::vector<std::string>& vec,
81 std::vector<T>& result, boost::false_type is_string)
84 result.reserve(vec.size());
85 for (
size_t i=0; i<vec.size(); ++i)
86 result.push_back(utility::convert<T>(vec[i]));
93 template<
typename DELIM,
typename T>
94 std::istream&
getvector(std::istream&
is, std::vector<T>& result,
95 DELIM delim,
char nl_delim)
98 if (!getline(
is, line, nl_delim))
100 std::vector<std::string> vec;
101 split(vec, line, delim);
102 typename boost::is_same<T, std::string> is_string;
103 convert(vec, result, is_string);
112 char delim,
char newlinedelim)
114 return detail::getvector(
is, result, delim, newlinedelim);
120 const std::string& delim,
char newlinedelim)
122 return detail::getvector(
is, result, delim, newlinedelim);
bool is(const std::string &s)
check if string is convertible to (numerical) type T
Definition: utility.h:589
The Department of Theoretical Physics namespace as we define it.
Some useful functions are placed here.
std::istream & getvector(std::istream &is, std::vector< T > &result, char delim, char newlinedelim='\n')
Definition: getvector.h:111
void split(std::vector< std::string > &result, const std::string &str, char delim)
split a string into several substrings
std::string convert(T input)
convert T to a string
Definition: utility.h:569