小编mwi*_*ebe的帖子

如何在visual C++ 2013中执行嵌套的initializer_lists

我有一个使用嵌套的initializer_list在g ++和clang中工作的程序.在Visual C++中,1D案例可行,但2D嵌套初始化列表不起作用.是否有一个技巧使Visual C++工作,或者这可能是他们的实现中的错误?

这是我的示例代码.如果我删除带注释的行,它在Visual C++ 2013中工作.

#include <iostream>
#include <initializer_list>

using namespace std;

template<class T>
void print(T val) {
    cout << val;
}

template<class T>
void print(initializer_list<T> lst) {
    bool first = true;
    cout << "[";
    for (auto i : lst) {
        if (!first) cout << ", ";
        print(i);
        first = false;
    }
    cout << "]";
}

template<class T>
void print(initializer_list<initializer_list<T>> lst) {
    bool first = true;
    cout << "[";
    for (auto i : lst) {
        if (!first) cout …
Run Code Online (Sandbox Code Playgroud)

c++ initializer-list visual-c++ c++11 visual-studio-2013

7
推荐指数
1
解决办法
332
查看次数

如何控制cython cdef类的模块/名称?

我正在使用cython将C++库暴露给python,方法是将所有包装器对象和函数放在内部模块中_pydynd,然后通过不同的python模块公开它们.
我想控制出现在这些扩展类中的模块和类的名称dynd.nd.array,例如,而不是_pydynd.w_array,它是包装类的内部名称.cython是否有机制来做到这一点?

我希望找到类似于在编写定义时如何重命名C/C++函数的东西,但我的搜索结果却变得干脆.生成的C++代码应该是不同的是tp_name这里的行:

static PyTypeObject __pyx_type_7_pydynd_w_array = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("_pydynd.w_array"), /*tp_name*/
  sizeof(struct __pyx_obj_7_pydynd_w_array), /*tp_basicsize*/
Run Code Online (Sandbox Code Playgroud)

更新:

如果我尝试直接重命名对象,会发生以下情况:

In [103]: nd.array.__name__
Out[103]: 'w_array'

In [104]: nd.array.__module__
Out[104]: 'dynd._pydynd'

In [105]: nd.array.__name__ = "array"
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-105-73d9172a0216> in <module>()
----> 1 nd.array.__name__ = "array"

TypeError: can't set attributes of built-in/extension type 'dynd._pydynd.w_array'

In [106]: nd.array.__module__ = "dynd.nd"
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-106-37f990658ede> in <module>()
----> 1 …
Run Code Online (Sandbox Code Playgroud)

c++ python cpython cython

7
推荐指数
1
解决办法
757
查看次数