Canoe
Comprehensive Atmosphere N' Ocean Engine
vectorize.hpp
Go to the documentation of this file.
1 #ifndef SRC_UTILS_VECTORIZE_HPP_
2 #define SRC_UTILS_VECTORIZE_HPP_
3 
4 // C/C++
5 #include <cstring>
6 #include <string>
7 #include <vector>
8 
10 template <typename A>
11 std::vector<A> Vectorize(const char* cstr, const char* delimiter = " ") {
12  std::vector<A> arr;
13  char str[1028], *p;
14  snprintf(str, sizeof(str), "%s", cstr);
15  p = std::strtok(str, delimiter);
16  while (p != NULL) {
17  arr.push_back(static_cast<A>(std::stof(p)));
18  p = std::strtok(NULL, delimiter);
19  }
20  return arr;
21 }
22 
23 template <>
24 std::vector<std::string> Vectorize(const char* cstr, const char* delimiter);
25 
26 #endif // SRC_UTILS_VECTORIZE_HPP_
#define A(i, j)
Definition: band_back_sub.c:18
std::vector< A > Vectorize(const char *cstr, const char *delimiter=" ")
split a string to a vector
Definition: vectorize.hpp:11