当前位置:网站首页>Template parameter package and function parameter package
Template parameter package and function parameter package
2022-06-30 02:35:00 【wodownload2】
template<typename... Args> //Args Is a template parameter package
void Show(Args... args) //args It's a function parameter package
{
int size = sizeof ...(args);
return;
}
int main()
{
Show(1, 2, "2");// correct
Show<>(1, 2, "2");// correct
Show<int>(1, 2, "2");// correct
Show<int, int>(1, 2, "2");// correct
Show<int, int, string>(1, 2, "2"); // correct
Show<int, int, int>(1, 2, "2"); // error
Show<int, int, int, int>(1, 2, "2"); // error
return 0;
}
The conclusion is that : Template parameter package , Can be less , But the upper .
#include<iostream>
#include <map>
#include <vector>
#include<algorithm>
#include<tuple>
using namespace std;
/*using family_id = uint32_t; using Entity = uint64_t; template<typename Entity, typename... Component> class XView { public: template<typename Action> void each(Action act) const { } }; template<typename...> class XSparse_Container; template<typename Entity> class XSparse_Container<Entity> { }; template<typename Entity, typename Component> class XSparse_Container<Entity, Component> : public XSparse_Container<Entity> { }; template<typename C> struct XWrapper final : XSparse_Container<Entity, C> { //XWrapper(framework* ref) noexcept }; using underlying_pool_type = XSparse_Container<Entity>; using pool_ptr = underlying_pool_type*; struct Pool_Data { family_id _component_id{ 0 }; pool_ptr _pool{ nullptr }; }; template<typename C> using Pool_Wrapper = XWrapper<std::decay_t<C>>; template<typename Entity> class XFramework { public: template<typename... Component> XView<Entity, Component...> view() { return { assure<Component>()... }; } template<typename Component> auto* assure() { const family_id type = 3;// get_type<Component>(); Pool_Data* p = nullptr; vector<Pool_Data> _pools; if (type >= _pools.size()) { _pools.reserve(type << 1); while (type >= _pools.size()) { _pools.emplace_back(); } } p = &_pools[type]; if (nullptr == p->_pool) { p->_component_id = type; p->_pool = new Pool_Wrapper<Component>(); } return static_cast<Pool_Wrapper<Component>*>(p->_pool); } }; template<typename... Component> XView<int, Component...> view() { return {}; };*/
void P(int a)
{
cout << a << endl;
}
inline void args_print(std::ostream& steam) {
}
template<typename T, typename ...Args>
inline void args_print(ostream& steam, T first, Args...rest) {
steam << first;
//steam << typeid(first).name << endl;
args_print(steam, rest...);// The remaining parameters call recursively
}
template<typename T>
void TT(T a)
{
std::cout << a << endl;
}
template<typename Entity, typename... Component>
class XView
{
public:
XView(Component ... args)
{
size = sizeof ...(args);
args_print(std::cout, args...);
}
template<typename Action>
void each(Action act) const
{
auto result = true;
//int size = sizeof ...();
//for (int i = 0; i < size; ++i)
((result ? each<Component>(std::move(act)) : void()), ...);
//(TT<Component>(act), ...);
}
template<typename C, typename Action>
void each(Action act) const
{
C c = 1;
int a = 1;
}
int size;
};
template<typename ComponentA, typename ComponentB>
int f()
{
return 1;
}
template<typename Entity, typename... Component>
XView<Entity, Component...> view()
{
//auto a = XView<Entity, Component...>(args...);
//return a;
//return { f<Component...>(),f<Component...>() };
return {
f<Component...>(), f<Component...>() };
//return { 3,4 };
}
class A
{
public:
A(int a, int b)
{
}
};
A f()
{
return {
1,2 };
}
template<typename T, typename ...B>
void func(B ... args)
{
int size = sizeof ...(args);
T a;
//B b;
//int size = sizeof ...(args);
//args_print(std::cout, args...);
}
#include <tuple>
template<typename ... T>
void SY()
{
std::tuple<T...> a;
}
class base
{
public:
int a;
};
class p1 : public base
{
public:
p1() {
a = 1; }
};
class p2 : public base
{
public:
p2() {
a = 2; }
};
void SY2(base b)
{
std::cout << b.a << std::endl;
}
template<typename ...T>
void SY1()
{
std::tuple<T...> a;
(SY2(std::get<T>(a)), ...);
}
template<typename T1, typename T2>
void addx(T1 t1, T2 t2)
{
//auto flag = is_same_v<T1, string>;
typedef conditional_t<is_same_v<T1, string>, int, string> TT;
TT t = "abc";
}
template<typename... Type>
struct type_list
{
static constexpr auto size = sizeof...(Type);
public:
type_list()
{
int a = 1;
int b = 2;
}
};
template<typename...>
struct type_list_cat {
public:
type_list_cat()
{
int a = 1;
}
};
template<typename... Type>
struct type_list_cat<type_list<Type...>>
{
public:
using type = type_list<Type...>;
int a = 1;
public:
type_list_cat(int x)
{
auto size1 = sizeof...(Type);
int a = 1;
int b = 2;
}
};
template<typename... Type, typename... Other, typename... List>
struct type_list_cat<type_list<Type...>, type_list<Other...>, List...>
{
using type = typename type_list_cat<type_list<Type..., Other...>, List...>::type;
public:
type_list_cat()
{
auto size1 = sizeof...(Type);
auto size2 = sizeof...(Other);
auto size3 = sizeof...(List);
int a = 1;
int b = 2;
}
};
template<typename ...>
class Person;
template<typename T>
class Person<T>
{
public:
Person(int x)
{
int a = 3;
int b = 3;
}
};
template<typename ...T>
class Student
{
public:
Student(T... args)
{
auto size1 = sizeof...(T);
}
};
int main()
{
/*Person<int> axx(3); type_list<int, int> d;*/
type_list_cat<int, int> xa(type_list<int, int>);
type_list_cat<int, int> test0;
type_list_cat<type_list<int, int>> test1(1);
type_list_cat<type_list<int, int, float>> test2(2);
type_list_cat<type_list<int>, type_list<int, int>, type_list<int, int, int>> test3;
type_list_cat<type_list<int>, type_list<int, int>, type_list<int, int, int>>::type test4;
int xxx = test4.size;
std::cout << typeid(test1).name() << std::endl;
std::cout << typeid(test2).name() << std::endl;
type_list_cat<type_list<int, int, float>>::type x;
//std::cout << typeid(xa).name() << std::endl;
func<string, string>("123", "456");
//addx<int>(1, 2);
//XView<string, int, int> xview(1, 1);
//float c = 10;
//xview.each(c);
std::cout << "t1 is {" << std::get<0>(t1) << ", " << std::get<1>(t1) << "}" << std::endl;
//std::tuple<int, string, string> t(1, "abc", "def");
//auto x = std::get<int>(t);
//auto y = std::get<1>(t); // Index must be passed , Because there are two string
//auto z = std::get<2>(t);
//SY1<p1, p2>();
return 0;
}
vector Of size and capacity
vector<int> v;
int size = v.size();
int capacity = v.capacity();
v.reserve(5);
v.emplace_back(1);
v.emplace_back(2);
v.emplace_back(3);
size = v.size();
int x = v.capacity();
template<typename...>
class XSparse_Container;
template<typename Entity>
class XSparse_Container<Entity>
{
public:
XSparse_Container() = default;
public:
int size() const {
return length;
}
int length;
};
template<typename Entity, typename Component>
class XSparse_Container<Entity, Component> : public XSparse_Container<Entity>
{
};
using Entity = uint64_t;
using underlying_pool_type = XSparse_Container<Entity>;
template<typename C>
using pool_type = XSparse_Container<Entity, C>;
template<typename Entity, typename... Component>
class XView
{
public:
tuple<pool_type<Component>*...> _pools;
XView(XSparse_Container<Entity, Component>*... ref) noexcept
:_pools{
ref... }
{
get_candidate();
}
underlying_pool_type* _candidate;
void get_candidate() noexcept
{
auto a = {
static_cast<underlying_pool_type*>(std::get<pool_type<Component>*>(_pools))... };
cout << typeid(a).name() << endl;
_candidate = std::min(a, [](const auto* lhs, const auto* rhs)
{
cout << typeid(lhs).name() << endl;
//return true;
return lhs->size() < rhs->size();
});
cout << _candidate->length << endl;
}
};
int main()
{
XSparse_Container<uint64_t, string> b;
XSparse_Container<uint64_t, int> c;
b.length = 2;
c.length = 3;
XView<uint64_t, string, int> x(&b,&c);
return 0;
}
边栏推荐
- 堆排序
- DHU programming exercise
- VScode如何Debug(调试)进入标准库文件/第三方包源码
- dhu编程练习
- What is digicert smart seal?
- 重看《Redis设计与实现》后记录几个要点
- Global and Chinese market of ERP software for garment and textile industries 2022-2028: Research Report on technology, participants, trends, market size and share
- 打造創客教育中精湛技藝
- How do PMP candidates respond to the new exam outline? Look!
- 模板参数包和函数参数包
猜你喜欢

每周推荐短视频:为什么理论正确但得不到预期结果?

Quick sort

2022年7月深圳地区CPDA数据分析师认证

Traffic, but no sales? 6 steps to increase website sales

什么是自签名证书?自签名SSL证书的优缺点?

Differences among digicert, SECTIONO and globalsign code signing certificates

Several key points recorded after reviewing redis design and Implementation

What files does a CA digital certificate contain? How to view SSL certificate information?

三层交换机和二层交换机区别是什么

希尔排序
随机推荐
dhu编程练习
快速排序
Network neuroscience -- a review of network Neuroscience
重看《Redis设计与实现》后记录几个要点
新考纲下的PMP考试有多难?全面解析
主流CA吊销俄罗斯数字证书启示:升级国密算法SSL证书,助力我国网络安全自主可控
Ffmpeg source code
Simple distinction between break and continue
Shenzhen CPDA Data Analyst Certification in July 2022
What is certificate transparency CT? How to query CT logs certificate logs?
Implementation of Sanzi chess with C language
模板参数包和函数参数包
Enlightenment from the revocation of Russian digital certificate by mainstream CA: upgrade the SSL certificate of state secret algorithm to help China's network security to be autonomous and controlla
Dynamic SQL
【postgres】postgres 数据库迁移
C语言 pivot_root的Invalid argument错误解决方案
银行的理财产品一般期限是多久?
002 color classification
FDA邮件安全解决方案
CMake教程系列-04-编译相关函数