小编tss*_*sch的帖子

julia - 如何找到Dict的最小/最大值的关键字?

我想找到与朱莉娅字典的最小值或最大值相对应的键.在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.

dictionary julia

8
推荐指数
3
解决办法
2611
查看次数

python.clang AST解析:获取字段声明的C++模板参数

我正在使用 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)

c++ python templates clang abstract-syntax-tree

5
推荐指数
1
解决办法
1534
查看次数