I came across a problem that I was unable to solve, at least to my satisfaction...
The best solution I've came up with so far involves using a macro. (I know...)
IDE: Visual Studio 2012
void main()
{
std::vector<int>; numbers;
numbers.push_back(100);
numbers.push_back(200);
numbers.push_back(300);
numbers.erase(std::remove(numbers.begin(), numbers.end(), 200), numbers.end());
Vector::Erase<int>(numbers, 200);
VECTOR_REMOVE(numbers, 200);
numbers.Remove(200);
numbers.clear();
}
namespace Vector
{
template <typename T>;
void Erase(std::vector<T>& source, T item)
{
source.erase(std::remove(source.begin(), source.end(), item), source.end());
}
}
#define VECTOR_REMOVE(vector, value) vector.erase(std::remove(vector.begin(), vector.end(), value), vector.end());
This problem extends far beyond this one example, thankfully, Boost has saved me from much of it, however, many problems still exist.
The real question of this topic:
Is a macro okay in the above scenario, if not, can someone point me towards a better solution that works, and uses the same or less amount of code as my current macro solution?
What about macros like this?
#define FOR(var, iterations) for (int var=0; var < iterations; ++var)
FOR(i, 10)
std::cout << "Hello World!" << std::endl;
I'm mainly using macros where snippets would probably work, however, macros produce less code 'visually' which makes for cleaner looking solutions, in my opinion.
Thoughts? Evil? Okay? Meh?
---
Note: I've searched Google, and most macro discussions mention logging\header guards, and math you shouldn't be doing with macros, none of the topics that I found addressed these types of solutions, and whether they were acceptable or not.
I'm actually undecided, that's why I'm asking for your advice on the matter, and perhaps, you guys can supply me with some other options that I've overlooked too. :D