模板元程式設計 第二章練習(非答案)

2021-07-07 07:48:34 字數 1869 閱讀 7514

boost::add_const 對引用沒有效果。。

#ifndef iter_swap_h

#define iter_swap_h

#include#include#include#include#includetemplatestruct doit;

templatestruct doit;

templatestruct doit;

templatestruct add_const_ref

;#endif

2-1. 編寫乙個三元元函式replace_type,它接收乙個任意的復合型別c作為其第乙個引數,

並將c中出現的所有type x替換為y

#pragma once

#include#include#include#include#includetemplatestruct replace_type;

templatestruct replace_type_imp

;templatestruct replace_type_imp;

templatestruct replace_type_imp;

templatestruct replace_type_imp;

templatestruct replace_type_imp;

templatestruct replace_type_imp;

templatestruct replace_type_imp;

templatestruct replace_type_imp;

templatestruct replace_type

;

2-2

#pragma once

#include#includetemplatestruct polymorphic_downcast_imp;

templatestruct polymorphic_downcast_imp;

templatestruct polymorphic_downcast_imp;

templatederived polymorphic_downcast(base x)

2-3,少了乙個const;

#pragma once

#includeusing std::string;

templatestruct type_descriptor_imp

;templateconst string type_descriptor_imp::value="unknow";

template<>

const string type_descriptor_imp::value="int";

template<>

const string type_descriptor_imp::value="short int";

template<>

const string type_descriptor_imp::value="char";

template<>

const string type_descriptor_imp::value="long int";

templatestruct type_descriptor

};templatestruct type_descriptor

};templatestruct type_descriptor

};templatestruct type_descriptor

};templatestruct type_descriptor

};templatestruct type_descriptor

};

模板元程式設計第四章練習(非答案)

4 0 using namespace std using namespace boost using namespace mpl placeholders templatestruct is a templatestruct is b int main templatestruct logical...

python核心程式設計第二章練習答案

迴圈和操作符 自己定義乙個列表的較簡單,下面的答案是使用者自己輸入列表 方法一sb 後來發現這種方法只能處理0 9的數字 方法二 但是這種只能每次輸入乙個數字 1 print 1 取五個數的和 n2 取五個數的平均值 nx 退出 option input please input your opti...

《C語言程式設計》第二章練習與習題答案

練2 1 include int main void 練2 2 printf programming is fun.and programming in c is even more fun n include int main void 練2 3 include int main void 練2 ...