A few days ago I asked by which criteria the compiler decides whether or not, to compute a constexpr function during compile time. When does a constexpr function get evaluated at compile time? As it turns out, a constexpr is only evaluated during compile-time, if all parameters are constant expressions and the variable you are assigning it to is are constant expression as well. template<t
几天前,我问编译器决定是否在编译期间计算一个constexpr函数。 什么时候在编译时对constexpr函数进行评估? 事实证明,如果所有参数都是常量表达式,并且您将其分配给的变量也是常量表达式,则只会在编译期间评估一个constexpr。 template<typename base_t, typename expo_t> constexpr base_t POW(base_t base, expo_t expo) { return (expo != 0 )? base * POW(base, expo -1) : 1; } template<typename T&
Consider the following code: #include <algorithm> #include <iostream> #include <vector> namespace my_space { struct A { double a; double* b; bool operator<(const A& rhs) const { return this->a < rhs.a; } }; void swap(A& lhs, A& rhs) { std::cerr << "My swap.n"; std::swap(lhs.a, rhs.a); std::swap(lhs.b, rhs.b)
考虑下面的代码: #include <algorithm> #include <iostream> #include <vector> namespace my_space { struct A { double a; double* b; bool operator<(const A& rhs) const { return this->a < rhs.a; } }; void swap(A& lhs, A& rhs) { std::cerr << "My swap.n"; std::swap(lhs.a, rhs.a); std::swap(lhs.b, rhs.b); } } int
Why does stable_sort need a copy constructor? ( swap should suffice, right?) Or rather, how do I stable_sort a range without copying any elements? #include <algorithm> class Person { Person(Person const &); // Disable copying public: Person() : age(0) { } int age; void swap(Person &other) { using std::swap; swap(this->age, other.age); } friend void swap(
为什么stable_sort需要一个拷贝构造函数? ( swap应该就够了,对吧?) 或者说,我怎么stable_sort一系列而不复制任何元素? #include <algorithm> class Person { Person(Person const &); // Disable copying public: Person() : age(0) { } int age; void swap(Person &other) { using std::swap; swap(this->age, other.age); } friend void swap(Person &a, Person &b)
I am looking for a C/C++ library. It should be able to parse C++ source code and generate abstract syntax tree. I would also like to explore/edit the AST from my program, for example to add a function call. This means, the syntax tree should not be in some text format, but as a collection of C++ objects, based on the object model of the library itself. It should also be able to generate C++
我正在寻找一个C / C ++库。 它应该能够解析C ++源代码并生成抽象语法树。 我也想从我的程序中探索/编辑AST,例如添加一个函数调用。 这意味着,语法树不应该是某种文本格式,而应该是基于库本身的对象模型的C ++对象的集合。 它也应该能够从AST生成C ++代码。 很显然,任何编译器都会这样做,并且可能有一些API。 我听说海湾合作委员会暴露了一些功能,但它在引擎盖下非常令人难以置信。 我知道艾尔莎,但是这个项目
I was wondering as to whether IO streams are really portable(I think they should be but want be sure) ? especially when handling files used in both unix and windows. Specifically if I dump a double value into a file in windows and then read the same value on unix from the file using iostreams, will it not cause problems because of variation in the endianness of the two operating systems ? wh
我想知道IO流是否真的是可移植的(我认为它们应该是可以肯定的)? 特别是在处理unix和windows中使用的文件时。 具体来说,如果我在Windows中将一个double值转储到文件中,然后使用iostreams从文件读取unix上相同的值,是否会因两个操作系统的字节序变化而引起问题? 格式化io怎么样? 我在某处读过,不知道在哪里,当操纵格式化数据时,windows和unix处理相同的方式存在一些差异。 任何人都可以请在这个问题上抛出一些光
I need to write a program to show a password window when user tries to access a file or folder in c++ for win XP & win 7 (for both 32bit and 64bit). But the difficult part is that I cannot use IAT EAT or inline hooking for this task as it is required to use a bit Microsoft supported method for this project. While googling for this, it was also mentioned in many forums that this can be acc
我需要编写一个程序来显示密码窗口,当用户试图访问一个文件或文件夹在c + + win XP和win 7(32位和64位)。 但困难的部分是我无法使用IAT EAT或内联挂钩来完成此任务,因为它需要使用Microsoft支持的此方法。 虽然googling为此,它也在许多论坛中提到,这可以使用文件系统过滤器驱动程序来完成,但我想知道如何从微型驱动程序显示密码对话框。 我认为外壳扩展可以完成这项工作,但是msdn文档显示外壳扩展不能用于拦截I /
( Note: As should already be clear from the tags, this is strictly C++03. Yes, I know, lambda makes all this pain go away (and brings in new kinds, I bet), but this is an embedded system, with an OS version from the 90s, and I am told I should be glad I have a C++03 compiler (GCC4.1.x, BTW), or a C++ compiler at all. So please abstain from posting C++11 solutions. No need to rub it in, really.
( 注意:从标签中应该已经清楚了,这完全是C ++ 03。是的,我知道,lambda使所有这些痛苦消失(并且带来了新的种类,我敢打赌),但这是一个嵌入式系统,与从90年代的操作系统版本,我被告知我应该很高兴我有一个C ++ 03编译器(GCC4.1.x,顺便说一句),或者一个C ++编译器,所以请放弃发布C ++ 11解决方案,无需揉搓,真的。 当然, std::bind() , std::function()等实际上在std::tr1 ,但是我编辑出了tr1前缀,因为我认为
I've been hacking up a raytracer for the first time over the past few days. However, there are a few quirks which bother me and I don't really know how to work out. One that has been there since the beginning is the shape of spheres in the scene - when rendered, they actually look like ovals. Of course, there is perspective in the scene, but the final shape still seems odd. I have att
在过去的几天里,我第一次打了一个光线追踪器。 然而,有一些怪癖困扰着我,我真的不知道如何解决。 从一开始就一直存在的是场景中的球体形状 - 渲染时,它们看起来像椭圆形。 当然,这个场景是有角度的,但最终的形状仍然很古怪。 我附加了一个示例渲染,我所遇到的问题在图像左下角的反射球体上特别明显。 我不知道可能是什么原因造成的。 它可能是射线球形交叉码,如下所示: bool Sphere::intersect(Ray ray, glm::ve
Consider the following code: struct A { int x; }; int main() { A a; A b{a}; } Is this program well-formed at C++11 standard? In my copy of N3797 it says 8.5.4 List initialization [dcl.init.list] 3: List-initialization of an object or reference of type T is defined as follows: - If T is an aggregate, aggregate initialization is performed (8.5.1). - Otherwise, if T is a specializa
考虑下面的代码: struct A { int x; }; int main() { A a; A b{a}; } 这个程序在C ++ 11标准中是否格式良好? 它说,在我的N3797副本 8.5.4列表初始化[dcl.init.list] 3:类型T的对象或引用的列表初始化定义如下: - 如果T是聚合,则执行聚合初始化(8.5.1)。 - 否则,如果T是std::initializer_list<E>的专门std::initializer_list<E> ,... - 否则,如果T是类类型,则考虑构造函数。 枚举适
I have this struct definitions: struct inner { int i; std::string str; }; struct outer { inner member[32]; }; Now I want to create a value-initialized instance of outer , so I write outer o = {}; With GCC, this works just fine: all inner.i are zeroed and all inner.str are empty. But on VS2013, only the inner.str are empty; all inner.i contain garbage ie are not properly initial
我有这个结构定义: struct inner { int i; std::string str; }; struct outer { inner member[32]; }; 现在我想创建一个outer值初始化的实例,所以我写了 outer o = {}; 使用GCC,这工作得很好:所有inner.i都归零,所有inner.str都是空的。 但在VS2013上,只有inner.str是空的; 所有inner.i包含垃圾,即没有正确初始化。 如果没有std::string成员, inner.i的零初始化可以与VS2013一起使用。 标准对此