Skip to content

Update main.cpp #53

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

knowledgaction
Copy link

  • vector逐元素相加:使用std::common_type_t<>,获得相加结果的返回值,然后就是两个vector按位置相加。
  • 两个variant相加:使用visit+lambda访问variant元素,调用上面定义"两个vector逐元素相加"的 +运算符;这里结果直接return,没有构造额外的variant对象。
  • variant+vector和vector+variant:这里实现的较冗余、重复,定义了较相似的两个函数;其实,就是通过vector构造variant对象,再调用“两个variant相加”的+运算符。
  • variant类型的,可变长度模板参数的<<重载:通过visit+lambda表达式访问,通过...修饰模板类型及参数;这里使用template <class T1,class... Targs>,确保至少有一个参数传进来,保证有参数传给<<进行重载。

hw3,磕磕绊绊,不太熟练地完成了。哈哈~~~

hw3,磕磕绊绊,不太熟练地完成了
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant