temporary

Does “T const&t = C().a;” lengthen the lifetime of “a”?

Deadly 提交于 2020-01-01 23:55:33
问题 The following scenario is given, to be interpreted as C++0x code: struct B { }; struct A { B b; }; int main() { B const& b = A().b; /* is the object still alive here? */ } Clang and GCC (trunk version as of 2011/02) behave differently: Clang lengthens the lifetime. GCC moves B to a new temporary object, and then binds the reference to that new temporary. I cannot find either behavior can be derived from the words of the Standard. The expression A().b is not a temporary (see 5.2.5). Can anyone

Does “T const&t = C().a;” lengthen the lifetime of “a”?

老子叫甜甜 提交于 2020-01-01 23:55:27
问题 The following scenario is given, to be interpreted as C++0x code: struct B { }; struct A { B b; }; int main() { B const& b = A().b; /* is the object still alive here? */ } Clang and GCC (trunk version as of 2011/02) behave differently: Clang lengthens the lifetime. GCC moves B to a new temporary object, and then binds the reference to that new temporary. I cannot find either behavior can be derived from the words of the Standard. The expression A().b is not a temporary (see 5.2.5). Can anyone

Temporary Modified Environment during External Process Call from Emacs

随声附和 提交于 2020-01-01 15:40:11
问题 Is there a convenient and functional ( with-... -like) way of temporary modifying environment variables when using shell-comand or start-process ? Thanks in advance, Per 回答1: server-with-environment looks promising. server-with-environment is a Lisp macro in `server.el'. (server-with-environment ENV VARS &rest BODY) Evaluate BODY with environment variables VARS set to those in ENV. The environment variables are then restored to their previous values. VARS should be a list of strings. ENV

When an array is created by a subexpression, what happens with the temporaries therein?

元气小坏坏 提交于 2020-01-01 07:37:24
问题 I was reading these two paragraphs of the FDIS (12.2p{4,5}): There are two contexts in which temporaries are destroyed at a different point than the end of the full-expression. The first context is when a default constructor is called to initialize an element of an array. If the constructor has one or more default arguments, the destruction of every temporary created in a default argument is sequenced before the construction of the next array element, if any. and The second context is when a

Return Ordering Without a vector

天涯浪子 提交于 2019-12-31 05:07:10
问题 So I am calling a helper function, vertex_triangle , quite a bit to allow me to take in a vector<pair<T, T>> and wind them into ordered triangles, then put those in a vector in that order. I'm using this as my return object: template <Typename T> struct Triangle { Triangle(const pair<T, T>& first, const pair<T, T>& second, const pair<T, T>& third) { data[0] = first; data[1] = second; data[2] = third; } pair<T, T> data[3]; }; So my winding helper function looks like this: template<typename T>

const reference to temporary oddity

谁说我不能喝 提交于 2019-12-30 04:36:29
问题 We all know that things like this are valid in c++: const T &x = T(); while: T &x = T(); is not. In a recent question the conversation lead to this rule. The OP had posted some code which clearly evokes UB. But I would have expect a modified version of it to work (This is the modified version): #include <iostream> using namespace std; class A { public: A(int k) { _k = k; }; int get() const { return _k; }; int _k; }; class B { public: B(const A& a) : _a(a) {} void b() { cout << _a.get(); }

Construction of temporary in function call is interpreted as declaration

穿精又带淫゛_ 提交于 2019-12-29 08:33:09
问题 Lately I ran into a problem which somehow (but only somehow) makes sense to me. It is based on interpreting the construction of a temporary as declaration of the single (!) constructor argument. Please have a look at the minimal example below. #include <iostream> class Foo0{ public: Foo0(int a){}; void doStuff() {std::cout<<"maap"<<std::endl;}; }; class Foo1{ public: Foo1(int a){}; void doStuff() {std::cout<<"maap"<<std::endl;}; }; class Foo2{ public: Foo2(int a){}; void doStuff() {std::cout<

Temporary table in PostgreSQL

余生颓废 提交于 2019-12-25 02:29:19
问题 I am trying to create temporary table in my function in postgreSQL. But getting an syntax error. The details as show below in example: Example: Create or replace function testing(a varchar(100),b varchar(100)) returns setof record as $$ Declare create temp table testtable(x int, y int identity(1,1), z varchar(100)); .... Error: Syntax error at or near "table". 回答1: You can only DECLARE variables. The CREATE TABLE (ddl) statement can only be run between the BEGIN - END blocks. 来源: https:/

How do I save temporary data on android?

拟墨画扇 提交于 2019-12-23 13:20:31
问题 How can I save some temporary data so that when I close the application all the data is gone? I've tried sharedPreferences but it seems that the data is still there when I open up the application once again. I've heard that you can save data to some cache memory, but I really don't want the data to be gone if the memory gets "filled" when the app is still up and running. Maybe I should go with some global variables? Not that I know how I could get that to work. My simple app, which is a "game

Will temporary object be deleted if there is no const reference to it?

三世轮回 提交于 2019-12-23 12:13:15
问题 Lets take a look to this two functions: std::string get_string() { std::string ret_value; // Calculate ret_value ... return ret_value; } void process_c_string(const char* s) { std::cout << s << endl; } And here are two possible calls of process_c_string with argument returned by get_string . Without binding const reference to the returned object of get_string . process_c_string(get_string().c_str()); With binding const reference to the returned object of get_string . const std::string& tmp