28template <
typename To,
typename From>
31 return std::shared_ptr<To>(ptr,
reinterpret_cast<To *
>(ptr.get()));
35inline std::ostream&
operator<<(std::ostream& os,
const uint8_t v)
37 os << static_cast<int>(v)
38 <<
"(0x" << std::hex << std::setfill(
'0') << std::setw(2)
39 <<
static_cast<int>(v) <<
")";
44inline std::ostream&
operator<<(std::ostream& os,
const std::vector<uint8_t>& v)
46 for (
int i = 0; i < static_cast<int>(v.size()); i++)
47 os << std::hex << std::setfill(
'0') << std::setw(2)
48 <<
static_cast<int>(v[i]);
53inline std::ostream&
operator<<(std::ostream& os,
const std::vector<int>& v)
55 for (
int i = 0; i < static_cast<int>(v.size()); i++)
56 os << std::hex << std::setfill(
'0') << std::setw(8)
57 <<
static_cast<int>(v[i]);
62inline std::ostream&
operator<<(std::ostream& os,
const std::vector<std::string>& v)
65 for (
auto it = v.begin(); it != v.end(); ++it)
76inline std::ostream&
operator<<(std::ostream& os,
const std::set<std::string>& s)
79 for (
auto it = s.begin(); it != s.end(); ++it)
90template<
class A,
class B>
92std::ostream&
operator<<(std::ostream& os,
const std::map<A, B>& s)
95 for (
auto it = s.begin(); it != s.end(); ++it)
99 os <<
"{" << it->first <<
", " << it->second <<
"}";
106template<
class A,
class B>
108std::ostream&
operator<<(std::ostream& os,
const std::map<const A, B>& s)
111 for (
auto it = s.begin(); it != s.end(); ++it)
115 os <<
"{" << it->first <<
", " << it->second <<
"}";
122template <
typename out>
123inline void split(
const std::string &s,
const std::regex& re, out result)
125 std::sregex_token_iterator d(s.begin(), s.end(), re, -1);
126 std::sregex_token_iterator end;
134inline std::string&
ltrim(std::string& s,
const char* t =
" \t\n\r\f\v")
136 s.erase(0, s.find_first_not_of(t));
142inline std::string&
rtrim(std::string& s,
const char* t =
" \t\n\r\f\v")
144 s.erase(s.find_last_not_of(t) + 1);
150inline std::string&
trim(std::string& s,
const char* t =
" \t\n\r\f\v")
std::string & ltrim(std::string &s, const char *t=" \t\n\r\f\v")
std::shared_ptr< To > reinterpret_pointer_cast(std::shared_ptr< From > const &ptr) noexcept
std::ostream & operator<<(std::ostream &os, const uint8_t v)
std::string & trim(std::string &s, const char *t=" \t\n\r\f\v")
std::string & rtrim(std::string &s, const char *t=" \t\n\r\f\v")
void split(const std::string &s, const std::regex &re, out result)