C++学习笔记 引用折叠与完美转发

完美转发仅仅发生于当调用该函数时会发生类型推倒

template<typename T>
void test(T&&a){

} 

如下情况CallService并不会发生完美转发

template<typename R,typename ...Paras>
class ServiceClient
{
    ReturnType<R> _returnVal;
    ParameterType<Paras...>_parameters;
  std::string _serviceName;
public:


   //this not a universival reference because this Paras is not dedeced in this function
  //but deduced in the class
    R CallService(const Paras&... p){

        Serializer Is;

        _parameters.serialize(&Is, p...);

        std::string s(Is.data(),Is.size());
        std::tuple<Paras...> items;
        int a;



        using args_type = std::tuple<typename std::decay<Paras>::type...>;

        Serializer ds(StreamBuffer(s.c_str(), s.size()));
        constexpr auto N = std::tuple_size<typename std::decay<args_type>::type>::value;
        args_type args = ds.get_tuple < args_type > (std::make_index_sequence<N>{});


         ++a;
         //get the serize parameters use _parameters
        //send to server
        //get the replay string
        //use _returnval  to un serlize the parameters from replay string
        //then get the ret val


    }




    R ServiceFunc(Paras&& ...p){

    }

    ServiceClient(std::string name){
        _serviceName = name;
        //get the service signature 
    }
};

原因是CallService的函数参数类型在定义 ServiceClient时就已经确定,此时在调用CallService不会发生类型推导。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值