国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

北大黃雨松同學(xué)的插件代碼的又一個(gè)知識(shí)點(diǎn):傳遞參的統(tǒng)一方式

2023-05-14 17:03 作者:盧朓  | 我要投稿

/**

?* 傳遞參數(shù)的統(tǒng)一方式,此方式可以用于北太天元插件的開(kāi)發(fā)。

?*/

#include <cstdlib>

#include <iostream>

#include <typeinfo>

#include <utility>

#include <array>

#include <vector>


using namespace std;


namespace ParseParams {

???template <class _T>

??????class FunTrait;

???template <typename R, typename... Args>

??????class FunTrait<R(Args...)>{

?????????public:

????????????static constexpr size_t n_args = sizeof...(Args);

?????????public:

?????????int required_params;

?????????std::array<void *, n_args> passed_args_ptr;

?????????//變量類型函數(shù)句柄, 變量名是decorated_func

?????????R(*decorated_func)

????????????(Args...);



?????????public:

?????????FunTrait(R (*func)(Args...), int num_required = 0){

????????????decorated_func = func;

??????????required_params = num_required;

?????????}


?????????template <size_t... I>

?????????R eval_impl(std::index_sequence<I...>){

????????????std::cout<<"需要的參數(shù)個(gè)數(shù)是 = " << required_params << std::endl;

????????????return decorated_func((Args)passed_args_ptr[I]...);

?????????}


?????????R eval(){

????????????return eval_impl(std::make_index_sequence<n_args>());

?????????}


?????????void check_in_args_type(const std::vector<void *> & a){

????????????for(size_t i=0; i<n_args; i++)

???????????????passed_args_ptr[i] = a[i];

?????????}


??????};

}


double f(){

???std::cout<<" f is a function "<<std::endl;

???return 1.0;

}


double g(const int * j){

???std::cout<<" *j = "<< *j<<std::endl;

???return (double)(*j);

}


char h(const int *j , const std::string?*str ){

???std::cout<<" *j = "<<*j << std::endl;

???std::cout<<" *str = "<<*str << std::endl;

???std::cout<<" (*str)[*j] = "<<(*str)[*j]<< std::endl;

???return (*str)[*j];

}


int main(){

???using namespace ParseParams;

???typedef FunTrait<decltype(f)> FT;

???//typedef FunTrait<double()> FT;


???FT t(f,0);

???t.eval();


???FunTrait<decltype(g)> s(g,1);

???int j = 4;

???const std::vector<void *> s_in_args ={(void *)&j};

???s.check_in_args_type(s_in_args);

???s.eval();


???FunTrait<decltype(h)> q(h,2);

???std::string str = "LOVE";

???int i = 1;

???const std::vector<void *> q_in_args ={(void *)&i, (void *)&str};

???q.check_in_args_type(q_in_args);

???q.eval();


???return 0;

}


北大黃雨松同學(xué)的插件代碼的又一個(gè)知識(shí)點(diǎn):傳遞參的統(tǒng)一方式的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
察隅县| 凌源市| 石景山区| 吴堡县| 射阳县| 江津市| 常山县| 文安县| 呼图壁县| 西乌珠穆沁旗| 白沙| 洞口县| 新蔡县| 邵东县| 阳原县| 桓台县| 高淳县| 八宿县| 鄂州市| 桃园县| 来安县| 社旗县| 嘉荫县| 威远县| 同心县| 长岭县| 永州市| 晋宁县| 吉木萨尔县| 南木林县| 普定县| 都安| 汽车| 宁安市| 车致| 馆陶县| 阿巴嘎旗| 福州市| 蒲江县| 从化市| 隆安县|