(I asked a variation of this question on comp.std.c++ but didn't get an answer.)
Why does the call to f(arg) in this code call the const ref overload of f?
void f(const std::string &); //less efficient
void f(std::string &&); //more efficient
void g(const char * arg)
{
f(arg);
}
My intuition says that the f(string &&) overload ...
Why does this:
#include <string>
#include <iostream>
using namespace std;
class Sandbox
{
public:
Sandbox(const string& n) : member(n) {}
const string& member;
};
int main()
{
Sandbox sandbox(string("four"));
cout << "The answer is: " << sandbox.member << endl;
return 0;
}
Give output of:
The answer is:
Ins...
Hi everyone,
I want to create a temporary clob. That's my function:
public static OracleLob CreateTemporaryClob(OracleConnection conn, OracleTransaction tx, string data)
{
OracleLob tempClob = null;
byte[] bData = new System.Text.ASCIIEncoding().GetBytes(data);
string cmdText = "declare a clob; begin dbms_lob.createtempora...
I tried following code :
#include<iostream>
#include<string>
using namespace std;
string f1(string s)
{
return s="f1 called";
}
void f2(string *s)
{
cout<<*s<<endl;
}
int main()
{
string str;
f2(&f1(str));
}
But this code doesn't compile.
What I think is : f1 returns by value so it creates temporary, of which I am taki...
Hi,
I have no clue whats going on here. My c# (VS2008) app runs fine in 32 bit OS but when i run the same in Windows 2008 R2 64bit i am getting following error:
Unable to generate a temporary class (result=1).
error CS0008: Unexpected error reading metadata from file 'c:\Windows\assembly\GAC_MSIL\xxxx\7.0.1001.0__5b72a65e64576834\xxxx....
It took me quite some time to understand the difference between an rvalue and a temporary object. But now the final committee draft states on page 75:
An rvalue [...] is an xvalue, a temporary object or subobject thereof, or a value that is not associated with an object.
I can't believe my eyes. This must be an error, right?
To ...
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...
Is the following code legal?
std::string&& x = "hello world";
g++ 4.5.0 compiles this code without any problems.
...
Hi,
I'm attempting to update a temporary table using a cursor that was declared 'for update'.
The update does not work: [Error Code: 7732, SQL State: 42W30] ASA Error -633: Update operation attempted on a read-only cursor
The sybase iq 12.7 docs says that the cursor becomes read-only under some circumstances, like for example if aggreg...
So for example, the user is logging in, and the system is storing informations about them example: birth date, so is faster to get this information from the session, or to query the database for it?
My idea was, that the user needs to login just once and the session is always there, but If I query the database, then if the user reloads...
The following segment demonstrates my issue: (compilation error on GCC)
stringstream ss;
string s;
ss << "Hello";
// This fails:
// s.swap(ss.str());
// This works:
ss.str().swap(s);
My error:
constSwap.cc:14: error: no matching function for call to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::swap(std::...
For what purpose I should use std::get_temporary_buffer? Standard says the following:
Obtains a pointer to storage sufficient to store up to n adjacent T objects.
I thought that the buffer will be allocated on the stack, but that is not true. According to the C++ Standard this buffer is actually not temporary. What advantages does ...
Here is what I mean, suppose I have code like:
for (int i = 0; i < 1000; i++) {
char* ptr = something;
/*
... use ptr here
*/
}
It seems that char* ptr gets allocated every time in the loop, making it ineffective?
Is it more effective to write this?
char* ptr = something;
for (int i = 0; i < 1000; i++) {
/*
....
Hi,
I am running Hadoop 0.20.1 under SLES 10 (SUSE).
My Map task takes a file and generates a few more, I then generate my results from these files. I would like to know where I should place these files, so that performance is good and there are no collisions. If Hadoop can delete the directory automatically - that would be nice.
Right...
In a previous question, you guys helped me grab data from a different row. The statement I am using works perfectly on the MS SQL Server Managment Studio. I can run the statement without any errors and I return the data I need. However, I need to run this data on our frontend program. When I try to run my statement on this program, it ju...
We are currently busy migrating from Visual Studio 2005 to Visual Studio 2010 (using unmanaged C/C++). This means that about half of our developers are already using Visual Studio 2010, while the other half is still using Visual Studio 2005. Recently, I came into a situation where a certain construction can be written in a clean way in...
CREATE TABLE tableA (
`key` int(11) NOT NULL,
`value` int(11) NOT NULL,
UNIQUE KEY Akeyvalue (`key`,`value`),
KEY Avalue (`value`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE tableB (
`key` int(11) NOT NULL,
`value` int(11) NOT NULL,
UNIQUE KEY Bkeyvalue (`key`,`value`),
KEY Bvalue (`value`)
) ENGINE=InnoDB DEFAULT CHARSET=l...
Is it possible to return a standard container from a function without making a copy?
Example code:
std::vector<A> MyFunc();
...
std::vector<A> b = MyFunc();
As far as I understand, this copies the return value into a new vector b. Does making the function return references or something like that allow avoiding the copy?
...
I am making a photo upload form. Before they begin, they have two choices. They can create a new gallery, OR they can choose from an existing gallery.
I was thinking the best way to lay this out would be two have two forms. One for the create one that would take them to the create page. That's easy, and practically done.
But the second...
I heard the temporary objects can only be assigned to constant references.
But this code gives error
#include <iostream.h>
template<class t>
t const& check(){
return t(); //return a temporary object
}
int main(int argc, char** argv){
const int &resCheck = check<int>(); /* fine */
typedef int& ref;
const ref error = check<int...