1 #ifndef _TIMBER_PYTHONIC 2 #define _TIMBER_PYTHONIC 9 #ifndef _STRUCT_TIMESPEC 10 #define _STRUCT_TIMESPEC 25 template <
typename IntType>
26 std::vector<IntType> Range(IntType start, IntType stop, IntType step) {
27 if (step == IntType(0)) {
28 throw std::invalid_argument(
"step for range must be non-zero");
31 std::vector<IntType> result;
33 while ((step > 0) ? (i < stop) : (i > stop)) {
50 template <
typename IntType>
51 std::vector<IntType> Range(IntType start, IntType stop) {
52 return Range(start, stop, IntType(1));
63 template <
typename IntType>
64 std::vector<IntType> Range(IntType stop) {
65 return Range(IntType(0), stop, IntType(1));
77 std::vector<std::string> Split(
const std::string& str,
char delim =
' ') {
78 std::vector<std::string> out {};
79 std::stringstream ss(str);
81 while (std::getline(ss, token, delim)) {
97 bool InList(T obj, std::vector<T> list) {
99 auto pos = std::find(std::begin(list), std::end(list), obj);
100 if (pos != std::end(list)){
102 }
else {out =
false;}
114 bool InString(std::string sub, std::string main) {
116 auto found = main.find(sub);
117 if (found != std::string::npos){
119 }
else {out =
false;}
131 void Extend(std::vector<T> base, std::vector<T> extension) {
132 for (
int i = 0; i < extension.size(); i++) {
133 base.push_back(extension.at(i));
144 bool IsDir(
char* dirname) {
148 if (stat(dirname, &sb) == 0 && S_ISDIR(sb.st_mode)) {
160 void Execute(std::string cmd) {
161 printf(
"Executing: %s",cmd.c_str());
162 std::system(cmd.c_str());
Definition: Pythonic.h:14