| 1 | // LAF Base Library |
| 2 | // Copyright (c) 2001-2016 David Capello |
| 3 | // |
| 4 | // This file is released under the terms of the MIT license. |
| 5 | // Read LICENSE.txt for more information. |
| 6 | |
| 7 | #ifndef BASE_REMOVE_FROM_CONTAINER_H_INCLUDED |
| 8 | #define BASE_REMOVE_FROM_CONTAINER_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | namespace base { |
| 12 | |
| 13 | // Removes all ocurrences of the specified element from the STL container. |
| 14 | template<typename ContainerType> |
| 15 | void remove_from_container(ContainerType& container, |
| 16 | typename ContainerType::const_reference element) |
| 17 | { |
| 18 | for (typename ContainerType::iterator |
| 19 | it = container.begin(), |
| 20 | end = container.end(); it != end; ) { |
| 21 | if (*it == element) { |
| 22 | it = container.erase(it); |
| 23 | end = container.end(); |
| 24 | } |
| 25 | else |
| 26 | ++it; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | } |
| 31 | |
| 32 | #endif |
| 33 | |