inline void remove_placeholders (ContainerT &replacement_list) { using namespace boost::wave; // strip leading whitespace if (replacement_list.size() > 0) { typename ContainerT::iterator end = replacement_list.end(); typename ContainerT::iterator it = replacement_list.begin(); while (it != end) { if (T_PLACEHOLDER == token_id(*it)) { typename ContainerT::iterator next = it; ++next; replacement_list.erase(it); it = next; } else { ++it; } } // remove all 'new' leading and trailing whitespace trim_replacement_list(replacement_list); } }
inline void trim_replacement_list (ContainerT &replacement_list) { using namespace boost::wave; // strip leading whitespace if (replacement_list.size() > 0) { typename ContainerT::iterator end = replacement_list.end(); typename ContainerT::iterator it = replacement_list.begin(); while (it != end && IS_CATEGORY(*it, WhiteSpaceTokenType)) { if (T_PLACEHOLDER != token_id(*it)) { typename ContainerT::iterator next = it; ++next; replacement_list.erase(it); it = next; } else { ++it; } } } // strip trailing whitespace if (replacement_list.size() > 0) { typename ContainerT::reverse_iterator rend = replacement_list.rend(); typename ContainerT::reverse_iterator rit = replacement_list.rbegin(); while (rit != rend && IS_CATEGORY(*rit, WhiteSpaceTokenType)) ++rit; typename ContainerT::iterator end = replacement_list.end(); typename ContainerT::iterator it = rit.base(); while (it != end && IS_CATEGORY(*it, WhiteSpaceTokenType)) { if (T_PLACEHOLDER != token_id(*it)) { typename ContainerT::iterator next = it; ++next; replacement_list.erase(it); it = next; } else { ++it; } } } }
void eraseElementsIf(ContainerT& container, const PredicateT& predicate) { auto iter = container.begin(); while(iter != container.end()) { if(predicate(*iter) == true) { iter = container.erase(iter); } else { ++iter; } } }
void erase_if(ContainerT& items, const PredicateT& predicate) { for(auto it = items.begin(); it != items.end();) { if(predicate(*it)) it = items.erase(it); else ++it; } };