#pragma once #include #include #include #include #include #include namespace ddkit { namespace utils { namespace container { template bool contains(Container container, Value value) { return std::find(container.begin(), container.end(), value) != container.end(); } template std::vector set2vector(std::set p_set) { std::vector r_vec; std::copy(p_set.begin(), p_set.end(), std::back_inserter(r_vec)); return r_vec; } template std::set vector2set(std::vector p_vec) { std::set r_set; std::copy(p_vec.begin(), p_vec.end(), std::inserter(r_set, r_set.begin())); return r_set; } template typename std::set set_difference(typename std::set const& minuend, typename std::set const& subtrahend) { std::set diff; std::set_difference( minuend.begin(), minuend.end(), subtrahend.begin(), subtrahend.end(), std::inserter(diff, diff.end())); return diff; } template typename std::vector vector_difference(typename std::vector const& minuend, typename std::vector const& subtrahend) { std::vector diff; std::copy_if(minuend.begin(), minuend.end(), std::back_inserter(diff), [subtrahend](const T& element) { return !contains(subtrahend, element); }); return diff; } inline std::string quotify(const std::string& input) { return "\"" + input+ "\""; } template T quotify(T t) { return t; } template std::ostream& operator<<(std::ostream& s, std::vector rhs) { bool isFirst = true; s << "["; for (auto const& i : rhs) { if (isFirst) isFirst = false; else s << ", "; s << quotify(i); } s << "]"; return s; } template std::ostream& operator<<(std::ostream& s, std::pair rhs) { return s << rhs.first << ":" << quotify(rhs.second); } template std::ostream& operator<<(std::ostream& s, std::map rhs) { bool isFirst = true; s << "{"; for (auto const& i : rhs) { if (isFirst) isFirst = false; else s << ", "; s << i; } s << "}"; return s; } template std::ostream& operator<<(std::ostream& s, std::set rhs) { bool isFirst = true; s << "["; for (auto const& i : rhs) { if (isFirst) isFirst = false; else s << ", "; s << quotify(i); } s << "]"; return s; } template std::ostream& operator<<(std::ostream& s, std::weak_ptr rhs) { if(rhs.expired()){ s << ""; } else { s << rhs.lock(); } return s; } } // container } // utils using ddkit::utils::container::operator<<; } // ddkit