C ++ 11 std :: prom returns std :: string from a stream, the data pointer looks copied not moved

I started playing with the C ++ 11 standard and the built-in stream. From what I collect when the value is obtained in the future, this is done with the help of a relocation operator giving ownership from the original object (for example, the old auto_ptr used to execute on assignment). I checked this by printing the char array pointer inside the std :: string object during the stream and printing the pointer after receiving it basically. However, the pointers are different. I would appreciate it if someone could tell me why they differ in this simple code and that the code should look so that they are equal:

#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>
#include <string>
#include <thread>
#include <future>
using namespace std;
void thrfut(promise<string>&& promReceived)
{
    string strObj("Hello from future");
    cout << "Address of char array inside string inside of thread " << (void*)strObj.data() << endl;
    promReceived.set_value(strObj);
}
int main(int argc, char** argv) 
{
    promise<string> promiseOfText;
    future<string> futureText = promiseOfText.get_future(); // has to be before creating thread if the promise is passed rvalue reference, should be moved on calling get or not ? 
    thread threadHandlingPromise(&thrfut, std::move(promiseOfText));
    string stringReceived = futureText.get();
    cout << "Received from promise through thread: " << stringReceived  << endl;
    cout << "Address of of char array inside string received from promise in main " << (void*)stringReceived.data() << endl;
    threadHandlingPromise.join(); 
    return 0;
}

Here is an example output

Address of char array inside string inside of thread 0x10ebc9be1
Received from promise through thread: Hello from future
Address of of char array inside string received from promise in main 0x7fff510f68c9

fyi: OS X 10.9.1 w/Xcode 5 clang++ Netbeans 8.0 Ubuntu Windows .

EDIT ( ) * * * * *

:

struct MYC 
{   MYC() = default;
    ~MYC() { delete _pInt; };
    MYC(const MYC & myc) { puts("MYC copy"); _pInt = nullptr; if(myc._pInt != nullptr) {   _pInt = new int{*myc._pInt}; } }  
    MYC(MYC && myc) { puts("MYC move"); delete _pInt; _pInt = myc._pInt; myc._pInt = nullptr; }
    void setMe(int value) { delete _pInt; _pInt = new int{value} ; }
    int * _pInt = nullptr;
};
void thrfut(promise<MYC>&& promReceived)
{
    MYC obj;
    obj.setMe(5);
    cout << "Address of int inside MYC inside thread " << (void*)obj._pInt << endl;
    promReceived.set_value(std::move(obj));    
}
int main(int argc, char** argv) 
{
    promise<MYC> promiseOfMYC;
    future<MYC> futureMYC = promiseOfMYC.get_future();  
    thread threadHandlingPromise(&thrfut, std::move(promiseOfMYC));
    auto mycReceived = futureMYC.get();
    cout << "Address of int inside MYC received from promise in main " << (void*)mycReceived._pInt << endl;
    cout << "Value of int inside MYC received from promise in main " << *(mycReceived._pInt) << endl;
    threadHandlingPromise.join(); 
    return 0;
}

:

Address of int inside MYC inside thread 0x7fd1b9c00110
MYC move
MYC move
Address of int inside MYC received from promise in main 0x7fd1b9c00110
Value of int inside MYC received from promise in main 5

.

+4
2

promReceived.set_value(strObj); string; .

promReceived.set_value(std::move(strObj));, , , data() . , , , .

(edit: ..)

+2

- , GNU libstd++ std::string . , - ? ( )

(1)

$ g++48 promiseStr.cpp -o promiseStr -Wall -Wextra -std=c++0x -O0 -g3 -pthread && echo OK
OK
$ ./promiseStr
Address of char array inside string inside of thread 0x7f4b400008d8
Received from promise through thread: Hello from future
Address of of char array inside string received from promise in main 0x7f4b400008d8

$ lsb_release -a
LSB Version: (snip)
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.2 LTS
Release:        12.04
Codename:       precise
$ g++48 --version
g++48 (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

(2) future<T>::get() T not &&T, stringReceived .

(3) ltrace Linux , (, OS X.)

$ ltrace -n2 -f -C ./promiseStr 2>&1 | grep basic_string
[pid 6899]       std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)(0x7f486c17fde0, 0x406ea0, 0x7f486c17fdef, 0x7f486c180700, 0x7f486c180700) = 0x7f48640008d8
[pid 6899]             std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)(0x244e0b0, 0x7f486c17fde0, 0x7f4864000900, 0x7f486c17fd90, 0x7f486c17fd20) = 0x7f48640008d8
[pid 6899]         std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()(0x7f486c17fde0, 0xffffffff, 0, 0x7f4864000028, 0x244e038 <unfinished ...>
[pid 6899]         <... std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() resumed> ) = 1
[pid 6898]   std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string&&)(0x7fff5c17ece0, 0x244e0b0, 0x244e0b0, -1, 0x244e038) = 0x7f486cf723d8
[pid 6898]   std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()(0x244e0b0, 1, 0x244e0a0, -1, 0x244e060) = 0x244e0b0
[pid 6898]   std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)(0x60bd40, 0x7fff5c17ece0, 0x7fff5c17ece0, 0x203a6461, 0x7f486c53cab0) = 0x60bd40
[pid 6898]       std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()(0x7fff5c17ece0, 0x7f486c759250, 0x7f486c180700, 0x7f486c759250, 0) = 0
+3

All Articles