64,701
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
#define MAX(a, b) ((a) > (b))? (a):(b)
void main()
{
int a=5, c=5, b=0;
MAX(++a, b);
cout<<a<<endl; //7
MAX(++c, b+10);
cout<<c<<endl; //6
}
看吧,不可思议吧!看看boost中的swap吧!
namespace boost_swap_impl
{
template<class T>
void swap_impl(T& left, T& right)
{
using namespace std;//use std::swap if argument dependent lookup fails
swap(left,right);
}
template<class T, std::size_t N>
void swap_impl(T (& left)[N], T (& right)[N])
{
for (std::size_t i = 0; i < N; ++i)
{
::boost_swap_impl::swap_impl(left[i], right[i]);
}
}
}
namespace boost
{
template<class T1, class T2>
void swap(T1& left, T2& right)
{
::boost_swap_impl::swap_impl(left, right);
}
}
typedef int (*ExchangeFunc)(void*,void*);
int exchange_int(int* a,int* b)
{
//...
return 0;
}
ExchangeFunc func = exchange_int;