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

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

用std的array代替原始的指針數(shù)組

2023-05-14 15:10 作者:盧朓  | 我要投稿

#include <cstdlib>

#include <iostream>

#include <typeinfo>

#include <utility>

#include <array>


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;

????????????/*

????????????passed_args_ptr = new void *[n_args] {};

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

???????????????passed_args_ptr[i] = nullptr;

????????????}

????????????*/

?????????}


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

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

????????????std::cout<<"需要的參數(shù)個數(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 int * a){

????????????passed_args_ptr[0] = (void *)a;

?????????}


?????????void check_in_args_type(const int * a, const std::string * str){

????????????if(passed_args_ptr[0] == nullptr){

???????????????std::cout<<"passed_args_ptr[0]的默認值是nullptr"<<std::endl;

????????????}

????????????if(passed_args_ptr[1] == nullptr){

???????????????std::cout<<"passed_args_ptr[1]的默認值是nullptr"<<std::endl;

????????????}

????????????passed_args_ptr[0] = (void *)a;

????????????passed_args_ptr[1] = (void *)str;

?????????}



??????};

}


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 a = 3;

???s.check_in_args_type(&a);

???s.eval();


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

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

???int i = 1;

???q.check_in_args_type(&i, &str);

???q.eval();


???return 0;

}


用std的array代替原始的指針數(shù)組的評論 (共 條)

分享到微博請遵守國家法律
宝丰县| 库尔勒市| 新化县| 安多县| 漳浦县| 合水县| 河池市| 苏尼特左旗| 新源县| 建湖县| 通江县| 沧州市| 获嘉县| 手机| 乾安县| 蒲江县| 平凉市| 手游| 阳泉市| 绍兴县| 涟源市| 嘉义县| 大兴区| 阳城县| 丹东市| 乌拉特后旗| 平武县| 四子王旗| 葫芦岛市| 霍邱县| 桐庐县| 临江市| 天镇县| 威宁| 中西区| 裕民县| 门头沟区| 如东县| 大同市| 巴林左旗| 南开区|