8#include <unordered_set>
12#define DEBUG_PRINTLN(msg) \
14 std::cerr << "[DEBUG] " << msg << std::endl; \
16#define DEBUG_PRINT(msg) \
18 std::cerr << "[DEBUG] " << msg; \
21#define DEBUG_PRINTLN(msg) \
24#define DEBUG_PRINT(msg) \
29#define WARN_PRINTLN(msg) \
31 std::cerr << "[WARN] " << msg << std::endl; \
39inline T&
indirect(
const std::unique_ptr<T>& ptr) {
51 std::string::const_iterator it = s.begin();
52 while (it != s.end() && std::isdigit(*it)) {
55 return !s.empty() && it == s.end();
61 }
else if (s ==
"true") {
65 return std::stoull(s);
71 }
else if (s ==
"true") {
78inline bool endswith(std::string
const& value, std::string
const& ending) {
79 if (ending.size() > value.size()) {
82 return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
85template<
class S,
class T>
86inline std::string
join(std::vector<T>& elems, S& delim) {
87 if (elems.size() == 0) {
91 typename std::vector<T>::iterator e = elems.begin();
93 for (; e != elems.end(); ++e) {
99inline void split(std::vector<std::string>& result, std::string s, std::string del =
" ") {
100 int start, end = -1 * del.size();
102 start = end + del.size();
103 end = s.find(del, start);
104 result.push_back(s.substr(start, end - start));
109inline bool sets_intersect(
const std::unordered_set<T>& set1,
const std::unordered_set<T>& set2) {
111 const std::unordered_set<T>& smaller = (set1.size() < set2.size()) ? set1 : set2;
112 const std::unordered_set<T>& larger = (set1.size() < set2.size()) ? set2 : set1;
115 for (
const T& element : smaller) {
116 if (larger.find(element) != larger.end()) {
bool is_number(const std::string &s)
Definition helpers.h:50
int64_t parse_number_signed(const std::string &s)
Definition helpers.h:68
const T & add_const(T &s)
Definition helpers.h:44
bool sets_intersect(const std::unordered_set< T > &set1, const std::unordered_set< T > &set2)
Definition helpers.h:109
std::string join(std::vector< T > &elems, S &delim)
Definition helpers.h:86
uint64_t parse_number_unsigned(const std::string &s)
Definition helpers.h:58
bool endswith(std::string const &value, std::string const &ending)
Definition helpers.h:78
void split(std::vector< std::string > &result, std::string s, std::string del=" ")
Definition helpers.h:99
T & indirect(const std::unique_ptr< T > &ptr)
Definition helpers.h:39