这是这个看似无辜的几行代码。
#include <iostream>
#include <string>
#include <unordered_map>
struct Tag
{
using name_t = std::string;
using tag_map_t = std::unordered_map<name_t, Tag>;
name_t name;
tag_map_t children = {};
};
int main(void)
{
auto foo = Tag{"foo"};
auto bar = Tag{"bar"};
foo.children["bar"] = bar;
std::cout << foo.name << " -> " << foo.children["bar"].name << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
? clang++ --version
clang version 11.0.1
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM\bin
? clang++ -std=c++14 -Weverything -Werror -Wno-c++98-compat tag.cpp -o tag.exe && …Run Code Online (Sandbox Code Playgroud)