我想找到与朱莉娅字典的最小值或最大值相对应的键.在Python中我会想到以下内容:
my_dict = {1:20, 2:10}
min(my_dict, my_dict.get)
Run Code Online (Sandbox Code Playgroud)
哪个会返回密钥2.
我怎么能在朱莉娅做同样的事情?
my_dict = Dict(1=>20, 2=>10)
minimum(my_dict)
Run Code Online (Sandbox Code Playgroud)
后者返回1 => 20而不是2 => 10或2.
我正在使用 clang 通过 python 接口提供的抽象语法树,尝试解析包含 std::vector 的简单结构:
#include <vector>
struct outer_t
{
std::vector<int> vec_of_ints;
};
Run Code Online (Sandbox Code Playgroud)
我想获取向量的模板参数,但在 AST 的相应节点中找不到对它的引用。get_num_template_arguments() 成员函数返回 -1。因此我认为 get_template_* 函数不能使用。我尝试了以下方法:
import sys
import clang.cindex
clang.cindex.Config.set_library_file("/usr/lib/llvm-6.0/lib/libclang.so.1")
class Walker:
def __init__(self, filename):
self.filename = filename
def walk(self, node):
node_in_file = bool(node.location.file and node.location.file.name == self.filename)
if node_in_file:
print(f"node.spelling = {node.spelling:14}, node.kind = {node.kind}")
if node.kind == clang.cindex.CursorKind.TEMPLATE_REF:
print(f"node.get_num_template_arguments = {node.get_num_template_arguments()}")
for child in node.get_children():
self.walk(child)
filename = sys.argv[1]
index = clang.cindex.Index.create()
translation_unit = index.parse(filename)
root = translation_unit.cursor
walker = Walker(filename) …Run Code Online (Sandbox Code Playgroud)