小编Yan*_*Zhu的帖子

一般来说,typedef可以用于矢量吗?

一般来说,我们可以做到

typedef std::vector<int> container1;
typedef std::vector<char> container2;
Run Code Online (Sandbox Code Playgroud)

但看起来我们不能做类似的事情.

typedef vector container;
container<int> ins;
Run Code Online (Sandbox Code Playgroud)

反正有没有实现这个目标?我能想到的是使用宏.

c++ typedef

2
推荐指数
1
解决办法
1150
查看次数

Python表示法或操作"**"

我看到了以下代码:

def __init__(self, fn, **kw):
     [setattr(self,k,v) for (k,v) in kw.items()]
     ......
Run Code Online (Sandbox Code Playgroud)

输入参数**kw是什么意思?

python

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

如何在浏览器中打开地址列表

我有一个链接列表,它存储在一个文件中.我想通过一些脚本打开浏览器中的所有链接,而不是手动复制粘贴每个项目.

例如,OS:MAC OS X; 浏览器:Chrome; 脚本:Python(首选)

python browser hyperlink

0
推荐指数
1
解决办法
1858
查看次数

使用boost python嵌入python时导入错误

我有以下代码

#include <boost/python.hpp>

int main()
{
    Py_Initialize();
    namespace python = boost::python;
    try {
        python::object main = python::import("sample");
    } catch(...) {
        PyErr_Print();
        PyErr_Clear();
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

ImportError: No module named sample
Run Code Online (Sandbox Code Playgroud)

我将我的 sample.py 放在与该程序相同的目录中。

c++ boost-python

0
推荐指数
1
解决办法
783
查看次数

Haskell函数和let语句

在GHCi中,我可以做到以下几点:

ghci> let ddd n = [0..n]
ghci> ddd 10
[0,1,2,3,4,5,6,7,8,9,10]
Run Code Online (Sandbox Code Playgroud)

但是,如果我在文件中定义类似的函数:

ddd :: Int -> [a]
ddd n = [0..n]
Run Code Online (Sandbox Code Playgroud)

在GHCi中加载文件后,我收到了以下错误

ghci> :l dsp.hs
[1 of 1] Compiling Main             ( dsp.hs, interpreted )

dsp.hs:43:13:
    Couldn't match expected type `a' with actual type `Int'
      `a' is a rigid type variable bound by
          the type signature for ddd :: Int -> [a] at dsp.hs:42:8
    In the expression: n
    In the expression: [0 .. n]
    In an equation for `ddd': ddd n …
Run Code Online (Sandbox Code Playgroud)

haskell

0
推荐指数
1
解决办法
153
查看次数

Rust 中带有 bool 和 usize 的通用常量表达式

我想定义一个类似的结构

pub struct ArInt<const W: usize, const S: bool>
{
   iarr : [i32; {(W + 31 + (!S))/32}],
}
Run Code Online (Sandbox Code Playgroud)

我遇到编译错误:

    --> src/ar_int.rs:7:27
  |
7 |     iarr : [i32; {(W + 31 + (!S))/32}],
  |                           ^ no implementation for `usize + bool`
  |
  = help: the trait `Add<bool>` is not implemented for `usize`
  = help: the following other types implement trait `Add<Rhs>`:
            <&'a usize as Add<usize>>
            <&usize as Add<&usize>>
            <usize as Add<&usize>>
            <usize as Add>
Run Code Online (Sandbox Code Playgroud)

我做了以下修改

    --> src/ar_int.rs:7:27
  |
7 | …
Run Code Online (Sandbox Code Playgroud)

rust

0
推荐指数
1
解决办法
87
查看次数

字符串中的有效Parenthese(Haskell实现)

问题是检查字符串中的括号是否正确关闭.对于Haskell实现,到目前为止我有以下内容.看起来很尴尬.我正在寻找更"Haskell风格"或更优雅的实现.

import Data.List

isValidParentheses :: String -> Bool
isValidParentheses = isValidHelper . (filter isParenthese)

getIndex :: (Eq a) => a -> [a] -> Int
getIndex c xs =  getOut (elemIndex c xs)
  where getOut (Just x) = x
        getOut Nothing = -1

isLeftParenthese :: Char -> Bool
isLeftParenthese c = (getIndex c "{[(") /= -1

isRightParenthese :: Char -> Bool
isRightParenthese c = (getIndex c "}])") /= -1

isParenthese :: Char -> Bool
isParenthese c = isLeftParenthese c || isRightParenthese …
Run Code Online (Sandbox Code Playgroud)

haskell

-1
推荐指数
1
解决办法
91
查看次数

标签 统计

c++ ×2

haskell ×2

python ×2

boost-python ×1

browser ×1

hyperlink ×1

rust ×1

typedef ×1