2-0.编写一个一元元函数 add_const_ref<T>,如果T是一个引用类型,就返回T,否则返回T const&。编写一个程序来测试你的元函数。提示:可以使用boost::is_same来测试结果。
boost::add_const 对引用没有效果。。
#ifndef ITER_SWAP_H
#define ITER_SWAP_H
#include<iterator>
#include<iostream>
#include<boost\type_traits\add_const.hpp>
#include<boost\type_traits\add_reference.hpp>
#include<boost\type_traits\is_reference.hpp>
template<bool,class T>
struct doit{
typename typedef T type;
};
template<class T>
struct doit<true,T>{
typename typedef T type;
};
template<class T>
struct doit<false,T>{
typename typedef boost::add_const<T>::type type1;
typename typedef boost::add_reference<type1>::type type;
};
template<class T>
struct add_const_ref
{
static const bool isR = boost::is_reference<T>::value;
typename typedef doit<isR,T>::type type;
};
#endif