本文整理汇总了C++中std::forward_list类的典型用法代码示例。如果您正苦于以下问题:C++ forward_list类的具体用法?C++ forward_list怎么用?C++ forward_list使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了forward_list类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: map
std::forward_list<B> map (std::function<B(A)> f, const std::forward_list<A>& L)
{
std::forward_list<B> H;
std::transform(L.begin(), L.end(), std::front_inserter(H), f);
H.reverse();
return H;
}
示例2: foldr_dest
U foldr_dest(std::function< U (U, T)>& op, const U& val, std::forward_list<T>& L)
{
if (L.empty()) return U(val);
T h = L.front();
L.pop_front();
return op (foldr(op, val, L), h);
}
示例3: extract
static void extract(const jsonpack::value &v, char* json_ptr, std::forward_list<T> &value)
{
array_t arr = *v._arr;
value.clear();
for(const auto &it : arr)
{
#ifndef _MSC_VER
// Initialize before use
T val = {};
#else
T val;
#endif
if( json_traits<T&>::match_token_type(it) )
{
json_traits<T&>::extract(it, json_ptr, val);
// forward_list not support insert operation
value.push_front(val);
}
else
{
throw type_error( "Forward_list item type mismatch" );
}
}
}
示例4: removeDupsNoBuffer
void removeDupsNoBuffer(std::forward_list<int>& l) {
if (l.empty())
return;
auto backtrack = l.before_begin();
while (std::next(backtrack) != l.end()) {
// Iterate and print values of the list
for (int n : l)
std::cout << n << '\t';
std::cout << std::endl;
auto prev = std::next(backtrack);
auto iter = std::next(prev);
//std::cout << " prev =" << *prev << ", iter=" << *iter << std::endl;
while (iter != l.end()) {
if (*iter == *std::next(backtrack))
iter = l.erase_after(prev);
else {
++prev;
++iter;
}
}
++backtrack;
}
}
示例5: removeDups
void removeDups(std::forward_list<int>& l) {
l.sort();
for (int n : l)
std::cout << n << '\t';
std::cout << std::endl;
l.unique();
}
示例6: collection_load_impl
typename boost::disable_if<
typename detail::is_default_constructible<
typename std::forward_list<T, Allocator>::value_type
>,
void
>::type
collection_load_impl(
Archive & ar,
std::forward_list<T, Allocator> &t,
collection_size_type count,
item_version_type item_version
){
t.clear();
boost::serialization::detail::stack_construct<Archive, T> u(ar, item_version);
ar >> boost::serialization::make_nvp("item", u.reference());
t.push_front(u.reference());
typename std::forward_list<T, Allocator>::iterator last;
last = t.begin();
ar.reset_object_address(&(*t.begin()) , & u.reference());
while(--count > 0){
detail::stack_construct<Archive, T> u(ar, item_version);
ar >> boost::serialization::make_nvp("item", u.reference());
last = t.insert_after(last, u.reference());
ar.reset_object_address(&(*last) , & u.reference());
}
}
示例7: SendMediaList
void AudioStreamingServer::SendMediaList(const std::shared_ptr<ISocket>& clientSocket, const std::string& keyword, const std::string& hostName) const {
const std::forward_list<const std::string*> files = audioLibrary->Search(keyword);
std::vector<std::string> urls;
urls.reserve(std::distance(files.begin(), files.end()));
int responseSize = 0;
for(const std::string* file : files) {
std::string encodedFile = urlCodec->EncodeURL(*file);
std::string url;
url.reserve(hostName.length() + encodedFile.length() + 9); //account 2 for '/', '\n' and 7 for 'http://'
url += "http://";
url += hostName;
url += '/';
url += encodedFile;
url += '\n';
responseSize += url.length();
urls.push_back(std::move(url));
}
HttpResponse response(HTTP_1_1, OK, M3U, responseSize, keyword + ".m3u");
SendResponseHeader(clientSocket, response);
for(const std::string& url : urls) {
clientSocket->Send(url.c_str(), url.size());
}
}
示例8: zip
std::forward_list<std::tuple<A,B>> zip (const std::forward_list<A>& L, const std::forward_list<B>& M)
{
std::forward_list<std::tuple<A,B>> H;
auto zipper = [] (const A& a, const B& b) {return std::make_tuple(a,b);};
std::transform(L.begin(), L.end(), M.begin(), std::front_inserter(H), zipper);
H.reverse();
return H;
}
示例9:
void
TraialPool::return_traials(std::forward_list< Reference< Traial > >& list)
{
for (auto it = list.begin() ; it != list.end() ; it = list.begin()) {
available_traials_.push_front(*it);
list.pop_front(); // 'it' got invalidated
}
}
示例10: iReturn
int iReturn(std::forward_list<int> l, int n){
int k = 0;
for(auto i = l.begin(); i != l.end(); ++i){
if(++k == std::distance(l.begin(), l.end()) - n + 1)
return *i;
}
}
示例11: startAutoWalk
void Creature::startAutoWalk(const std::forward_list<Direction>& listDir)
{
listWalkDir = listDir;
size_t size = 0;
for (auto it = listDir.begin(); it != listDir.end() && size <= 1; ++it) {
size++;
}
addEventWalk(size == 1);
}
示例12: TEST
TEST(std_forward_list, clear) {
std::forward_list<int> l1{0, 0, 0, 0};
const std::forward_list<int> l2{1, 2, 3};
l1.clear();
ASSERT_TRUE(l1.begin() == l1.end());
l1.insert_after(l1.before_begin(), l2.begin(), l2.end());
ASSERT_TRUE(l1 == l2);
}
示例13: iReverse
//Iterative
void iReverse(std::forward_list<int> &l){
std::forward_list<int> s = l, r;
for(auto i = l.begin(); i != l.end(); ++i) //Iterate, pop and push into r
{
r.push_front(s.front());
s.pop_front();
}
l = r; //Assign s to l
}
示例14: save
inline void save(
Archive & ar,
const std::forward_list<U, Allocator> &t,
const unsigned int file_version
){
const collection_size_type count(std::distance(t.cbegin(), t.cend()));
boost::serialization::stl::save_collection<
Archive,
std::forward_list<U, Allocator>
>(ar, t, count);
}
示例15: get
void get(int k){
termStack.sort(std::greater<node>());
for(int i=0; i<k; i++){
cout<<termStack.front().t<<endl;
termStack.pop_front();
}
}