Sublime Text with console input for c++ programs

How can I use console input in SublimeText 2.0.1? I'v chosen "Tools -> Build System -> C++", and add hello.cpp file to the project: #include <iostream> int main() { int a, b, c; std::cout << "Enter: "; std::cin >> a >> b; c = a + b; std::cout << a << '+' << b << '=' << c << std::endl; return

崇高的文本与c + +程序的控制台输入

如何在SublimeText 2.0.1中使用控制台输入? 我选择了“工具 - >构建系统 - > C ++”,并将hello.cpp文件添加到项目中: #include <iostream> int main() { int a, b, c; std::cout << "Enter: "; std::cin >> a >> b; c = a + b; std::cout << a << '+' << b << '=' << c << std::endl; return 0; } 构建成功,但是当我运行(“工

Restrict pointers and inlining

I have tried to use restrict qualified pointers, and I have encountered a problem. The program below is just a simple one only to present the problem. The calc_function uses three pointers, which is restricted so they "SHALL" not alias with each other. When compiling this code in visual studio, the function will be inlined, so for no reason Visual Studio 2010 ignores the qualifiers.

限制指针和内联

我试图使用限制合格的指针,我遇到了一个问题。 下面的程序仅仅是一个简单的问题。 calc_function使用三个指针,这些指针是受限制的,因此它们“应该”不会彼此混淆。 在Visual Studio中编译此代码时,该函数将被内联,因此无论如何,Visual Studio 2010都会忽略限定符。 如果我禁用内联,代码执行速度会提高六倍(从2200ms到360ms)。 但我不想在整个项目中禁用内联,也不想在整个文件中禁用内联(因为那样会在例如所有gett

How to implement LFU cache using STL?

I'm trying to implement LFU (Least Frequently Used) cache using pure STL (I don't want to use Boost!). Requirements are: Associative access to any element using a Key like with std::map . Ability to release the lowest priority item (using its UsesCount attribute). Ability to update priority ( UsesCount ) of any item. The problems are: If I use std::vector as container of items

如何使用STL实现LFU缓存?

我试图使用纯STL实现LFU(Least Frequently Used)缓存(我不想使用Boost!)。 要求是: 使用Key与std::map关联访问任何元素。 能够释放最低优先级的项目(使用它的UsesCount属性)。 能够更新任何项目的优先级( UsesCount )。 问题是: 如果我使用std::vector作为容器的项目( Key , Value , UsesCount ), std::map作为容器的迭代器,用于关联访问的vector和std::make_heap , std::push_heap和std::pop_hea

memory image decrease

I am running this code: #include <iostream> #include <cstddef> int main(int argc, char *argv[]){ int a1=0, a2=0; int a3,a4; int b1=++a1; int b2=a2++; int*p1=&a1; int*p2=&++a1; size_t st; ptrdiff_t pt; int i=0; while(true){ printf("i: %d",i++); } printf("nni now is: %dn",i); return 0; } why do I observe such de

记忆影像减少

我正在运行此代码: #include <iostream> #include <cstddef> int main(int argc, char *argv[]){ int a1=0, a2=0; int a3,a4; int b1=++a1; int b2=a2++; int*p1=&a1; int*p2=&++a1; size_t st; ptrdiff_t pt; int i=0; while(true){ printf("i: %d",i++); } printf("nni now is: %dn",i); return 0; } 为什么我观察到图像记忆(fiol

Initializing an array with a constexpr?

I wonder if it is possible to initialize an entire array with a constexpr function (with C++ 2011). Here I have something to illustrate what I want to do : template<unsigned int DIM> const unsigned int MyClass<DIM>::_myVar[2][3] = { {metaFunction(0, 0, DIM), metaFunction(0, 1, DIM), metaFunction(0, 2, DIM)}, {metaFunction(1, 0, DIM), metaFunction(1, 1, DIM), metaFunction(1, 2, DIM)

用constexpr初始化一个数组?

我想知道是否可以使用constexpr函数初始化整个数组(使用C ++ 2011)。 在这里我可以说明我想要做的事情: template<unsigned int DIM> const unsigned int MyClass<DIM>::_myVar[2][3] = { {metaFunction(0, 0, DIM), metaFunction(0, 1, DIM), metaFunction(0, 2, DIM)}, {metaFunction(1, 0, DIM), metaFunction(1, 1, DIM), metaFunction(1, 2, DIM)} }; template<unsigned int DIM> inline constexpr

How does boost::asio::io

I am using boost::asio::io_service to manage some asynchronous TCP communication. That means I create a boost::asio::ip::tcp::socket and give the io_service to it. When I start the communication it goes schematically like this: Async Resolve -> Callback -> Async Connect -> Callback -> Async Write -> Callback -> Async Read I ommitted parts like resolve and bind. Just assum

boost :: asio :: io如何?

我使用boost::asio::io_service来管理一些异步TCP通信。 这意味着我创建一个boost::asio::ip::tcp::socket并将io_service赋予它。 当我开始沟通时,它就是这样示意的: Async Resolve -> Callback -> Async Connect -> Callback -> Async Write -> Callback -> Async Read 我省略了像解析和绑定等部分。 假设Socket已经被绑定到一个端口并且主机名被解析了(所以连接意味着建立到端点的真实连接) 现

Strict aliasing and std::array vs C

When compiling the following code with gcc 4.7 (g++-mp-4.7 (GCC) 4.7.0 built with MacPorts on OS X) I get seemingly contradictory results. The compiler does not complain when I try to reinterpret and dereference a section of an std::array as an uint32_t but it does when using a C-style array. Example code: #include <array> #include <cstdint> int main() { std::array<ui

严格的别名和std :: array与C

当使用gcc 4.7(g ++ - mp-4.7(GCC)4.7.0使用OS X上的MacPorts构建)编译以下代码时,我看到了看似矛盾的结果。 编译器不会抱怨,当我尝试重新解释和解引用一个std::array作为uint32_t但它使用C风格的数组时。 示例代码: #include <array> #include <cstdint> int main() { std::array<uint8_t, 6> stdarr; *reinterpret_cast<uint32_t*>(&stdarr[0]) = 0; // OK uint8_

How to call constructor if function has the same name

If I have the following: class T { public: T(){} }; void T() { } int main() { T(); // this calls the function, how can I call the constructor T()? } I have no any issue with it, since I could be possible to rename it, but just curious how I could force it to call the constructor, and also I am asking to myself why the function call seems to have higher priority than the constructo

如果函数具有相同的名称,如何调用构造函数

如果我有以下情况: class T { public: T(){} }; void T() { } int main() { T(); // this calls the function, how can I call the constructor T()? } 我没有任何问题,因为我可以重命名它,但只是好奇我怎样才能强制它调用构造函数,而且我问自己为什么函数调用似乎比构造函数具有更高的优先级。 另外,为什么没有关于重复名称的警告消息。 除了jaunchopanza所说的,你可以限定这个电话: T::T(); 有了

More succinct way to use shims in variadic templates?

C++ templates are generally assimilated to creators of bloat, and the Shim idea deals with exactly that: making the template just a thin wrapper over a regular function. It's a really great way to cut down on the bloat. For example, let's use a simple shim: // // Shim interface // struct Interface { virtual void print(std::ostream& out) const = 0; }; // struct Interface std::

在variadic模板中使用垫片更简洁的方法?

C ++模板通常与膨胀的创建者同化,而Shim的想法正好处理:使模板仅仅是一个常规函数的薄包装。 这是一个减少膨胀的好方法。 例如,让我们使用一个简单的垫片: // // Shim interface // struct Interface { virtual void print(std::ostream& out) const = 0; }; // struct Interface std::ostream& operator<<(std::ostream& out, Interface const& i) { i.print(out); return out; } t

extremely strange machine code behaviour

The full code is here: http://pastebin.com/MM3vWmqA In the function fast_generator I've added comments to two statements. If you switch those statements, the code will run ~1.8x faster. If you remove the first statement the code will perform faster than the original version, but slower compared to if they were switched. The test cases should be the following. First - slowest. 452ms.

非常奇怪的机器代码行为

完整的代码在这里:http://pastebin.com/MM3vWmqA 在函数fast_generator中,我添加了两条语句的注释。 如果您切换这些语句,代码将运行速度加快〜1.8倍。 如果删除第一条语句,代码将比原始版本执行得更快,但与切换后的代码相比要慢一些。 测试用例应该如下。 首先 - 最慢。 452ms。 counter++; i--; 其次 - 比第一个更快。 280ms。 i--; counter++; 第三 - 比第一个快,但比第二个慢。 421ms。 i--; 原始语句