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

hw03 #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

hw03 #37

wants to merge 1 commit into from

Conversation

Uuq114
Copy link

@Uuq114 Uuq114 commented Feb 23, 2022

std::variant 类似于 union,可以存储范围内的一种类型的值。
在使用时,需要判断 variant 存了哪种类型的值,可以使用 indexholds_alternative
更简单的方法是使用std::visit,visit 会自动用相应的类型调用 lambda
visit 中的 lambda 可以有多个 variant 的参数,而且 lambda 还可以有返回值,可以进一步简化代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant