---
title: "C++ stl中remove的实现"
author: "7090"
date: "2013-09-24T23:14:05Z"
tags: []
categories: ["编程语言"]
slug: "c-stl-remove"
draft: false
lastmod: "2013-09-24T23:14:05Z"
id: 1946869
url: "https://7090.iteye.com/blog/1946869"
---

原文：http://www.cplusplus.com/reference/algorithm/remove/

c++98中的实现：

template <class ForwardIterator, class T>
  ForwardIterator remove (ForwardIterator first, ForwardIterator last, const T& val)
{
  ForwardIterator result = first;
  while (first!=last) {
    if (!(*first == val)) {
      *result = *first;
      ++result;
    }
    ++first;
  }
  return result;
}