So, I have a macro.
// swap_specialize.hpp
#include <algorithm>
#ifndef STD_SWAP_SPECIALIZE
#define STD_SWAP_SPECIALIZE( CLASSNAME ) \
namespace std { \
template<> inline \
void swap( CLASSNAME & lhs, CLASSNAME & rhs ) \
{ lhs.swap(rhs); } }
#endif
So then I have a class
// c.hpp
#include <vector>
#include "swap_specialize.hpp"
class C
{
public:
C();
void swap(C& rhs)
{
data_.swap(rhs.data_);
}
C& operator=(C rhs)
{
rhs.swap(*this);
return *this;
}
private:
std::vector<int> data_;
}
STD_SWAP_SPECIALIZE(C)
Is it bad, stylistically, to do this? Is it a code smell? Or is it an OK practice?