add s_multiset
This commit is contained in:
@@ -21,4 +21,10 @@ int main(int argc, char *argv[])
|
|||||||
hack::container::v_multiset(v, "asdf", "qwer", "zcv");
|
hack::container::v_multiset(v, "asdf", "qwer", "zcv");
|
||||||
for(const auto& c : v) std::cout << c << std::endl;
|
for(const auto& c : v) std::cout << c << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{// ex: s_multiset
|
||||||
|
std::set<int> s;
|
||||||
|
hack::container::s_multiset(s, 1, 2, 3, 3, 2, 1);
|
||||||
|
for(const auto& c : s) std::cout << c << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace hack::container
|
namespace hack::container
|
||||||
{
|
{
|
||||||
template<typename Range, typename... Args>
|
template<typename Range, typename... Args>
|
||||||
void v_multiset(Range& r, Args... args)
|
void v_multiset(Range& r, Args... args)
|
||||||
{
|
{
|
||||||
std::size_t t = sizeof... (args);
|
constexpr std::size_t t = sizeof... (args);
|
||||||
r.reserve(t);
|
r.reserve(t);
|
||||||
(r.emplace_back(std::forward<Args>(args)), ...);
|
(r.emplace_back(std::forward<Args>(args)), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Range, typename... Args>
|
||||||
|
void s_multiset(Range& r, Args... args)
|
||||||
|
{
|
||||||
|
(r.insert(args), ...);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "string.hpp"
|
#include "string.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace hack::string
|
namespace hack::string
|
||||||
{
|
{
|
||||||
v_str split_str(const std::string& str, char t)
|
v_str split_str(const std::string& str, char t)
|
||||||
@@ -15,9 +17,7 @@ namespace hack::string
|
|||||||
begin = ++end;
|
begin = ++end;
|
||||||
end = str.find_first_of(t, begin);
|
end = str.find_first_of(t, begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
v.emplace_back(str.substr(begin));
|
v.emplace_back(str.substr(begin));
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user