int SWAR(unsigned int i)
{
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}
Run Code Online (Sandbox Code Playgroud)
我已经看到这个代码计算的位数等于132位整数,我注意到它的性能优于__builtin_popcount但我无法理解它的工作方式.
有人可以详细解释这段代码是如何工作的吗?
假设我的haskell项目目录中有以下脚本:
#!/usr/bin/env stack
-- stack --resolver lts-12.5 script
-- some imports here
main :: IO ()
main = do
-- some code here
Run Code Online (Sandbox Code Playgroud)
我想使用stack.yaml项目目录中存在的文件,以获取所需的包,因为我想从特定的git提交中获取它们而不是lts-12.5.
我尝试过添加--stack-yaml stack.yaml,--resolver lts-12.5但是当我运行脚本时,我收到了这个警告:Ignoring override stack.yaml file for script command: stack.yaml.
是否可以将我的stack.yaml文件用于脚本?或者是否可以指定我想从中获取包的git提交(比如使用locationwith commit和gitinside stack.yaml)?
我认为chr在其参数不是Unicode标量值的情况下,应该有一个函数可以工作但失败.
我通常用这种方式编写自己的函数:
toUnicode :: Int -> Maybe Char
toUnicode x
-- Ranges from "The Unicode Standard".
-- See definition D76 in Section 3.9, Unicode Encoding Forms.
| x >= 0 && x <= 0xD7FF = Just (chr x)
| x >= 0xE000 && x <= 0x10FFFF = Just (chr x)
| otherwise = Nothing
Run Code Online (Sandbox Code Playgroud)
但如果有更好的方法可以做到这一点会很好.
我以前使用Microsoft Visual Studio 2005编写C++代码,其中auto-indent的行为非常好.
但是当我尝试使用Code :: Blocks时,我意识到自动缩进的行为很糟糕.
例如,困扰我的事情之一:
for (int i = 0; i < n; i++)
//it start from here in Code::Blocks
for (int i = 0; i < n; i++)
//I want it to start from here like in Visual Studio
Run Code Online (Sandbox Code Playgroud)
同样的事情if和while
有没有办法改变Code :: Blocks中自动缩进的行为,所以它会像Microsoft Visual Studio自动缩进一样好?
如何在执行后停止Visual Studio 2012关闭控制台窗口而不使用system("pause");?
问题1:如果我有这样的C++代码
#include <iostream>
using namesapce std;
int main() {
int a;
cin >> a;
cout << a << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不知道这是否被调用(调试,编译或构建),但我只是想在gvim中运行这个程序,所以我可以给它输入并查看输出,并查看错误,例如"missing';' "或"缺少'}'"(就像我在"Code :: Blocks"中单击F9时会发生的情况).exe文件,等等对我来说并不重要.
问题2:如果我有一个C++代码,我每次写这样的代码
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
Run Code Online (Sandbox Code Playgroud)
每次用vim打开.cpp文件时,如何让vim插入此代码?
我有Windows 7 32位和我的.vimrc文件是我安装vim时的默认文件.请尽可能详细.
c++ ×3
haskell ×2
algorithm ×1
c ×1
codeblocks ×1
editor ×1
indentation ×1
unicode ×1
vim ×1
windows ×1