小编nil*_*cit的帖子

什么时候应该在C++中使用函数而不是函子?

由于编译器更容易内联函数,因此函数显然更有效,并且它们在参数化方面的工作效果更好.什么时候应该使用普通的旧函数而不是函子?

c++ c++11

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

为什么这个Haskell代码这么慢?

我是Haskell的新手,并尝试制作拼字游戏解算器.它接收您当前拥有的字母,查找它们的所有排列并过滤掉那些字典单词.代码非常简单:

import Data.List

main = do
    dict    <- readFile "words"
    letters <- getLine
    let dictWords = words dict
    let perms = permutations letters
    print [x | x <- perms, x `elem` dictWords]
Run Code Online (Sandbox Code Playgroud)

然而,与我使用Python的非常类似的实现相比,它的速度非常慢.有什么根本我做错了吗?

*编辑:这是我的Python代码:

from itertools import permutations

letters = raw_input("please enter your letters (without spaces): ")

d = open('words')
dictionary = [line.rstrip('\n') for line in d.readlines()]
d.close()

perms = ["".join(p) for p in permutations(letters)]

validWords = []

for p in perms:
    if p in dictionary: validWords.append(p)


for validWord in …
Run Code Online (Sandbox Code Playgroud)

python optimization haskell language-comparisons

6
推荐指数
2
解决办法
476
查看次数

可以在类中使用外部变量吗?

在 C++ 中,是否可以将类成员变量标记为 extern?

我能有......吗

class Foo {
    public:
        extern string A;
};
Run Code Online (Sandbox Code Playgroud)

字符串 A 在我包含的另一个头文件中定义的位置?

c++ extern c++11

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

滚动到Facebook消息的顶部

是否有一些我可以执行的JavaScript代码滚动到Facebook上消息框的顶部?因此,当您单击"查看全部"并转到主消息页面时,如果向上滚动则会加载更多消息.我想强制它继续向上滚动以继续加载消息.我试过了

document.body.scrollTop = document.documentElement.scrollTop = 0;

但那当然只滚动到实际页面的顶部.有关如何滚动消息框的任何想法?

javascript scroll facebook

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