Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于模板展开的想法 #46

Open
Toin1779712664 opened this issue Nov 15, 2024 · 3 comments
Open

关于模板展开的想法 #46

Toin1779712664 opened this issue Nov 15, 2024 · 3 comments
Labels
invalid 这似乎不对 issue-resolved 问题已解决

Comments

@Toin1779712664
Copy link

第一章中的模板展开为什么不使用通俗易懂的方式让新晋模板选手可以更好的理解呢?
第一章内容如下:

template<typename...Args>
 void print(const Args&...args){    
     int _[]{ 0, (std::cout << args << ' ' ,0)... };
 }

更改通俗易懂的代码示例:

template<typename T>
void print(T& t){
    cout<<t<<endl;
}
template<typename...Args>
void print(const Args&...args){
    (cout<<...<<args);
}

这样的代码难道不比上面多声明一个数组的方式更好吗?

@Toin1779712664
Copy link
Author

@Mq-b

@Mq-b
Copy link
Owner

Mq-b commented Nov 15, 2024

你是不是对 “通俗易懂” 有什么误解?

@Yuzhiy05
Copy link

Yuzhiy05 commented Nov 15, 2024

仅需要先了解下,“副作用”和“逗号表达式”。同时我觉得二元折叠表达式在模板初学者看来并不比形参包展开更通俗易懂。当然什么更易懂本来就是个主观问题。

@Mq-b Mq-b added invalid 这似乎不对 issue-resolved 问题已解决 labels Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid 这似乎不对 issue-resolved 问题已解决
Projects
None yet
Development

No branches or pull requests

3 participants