msvc2010 and C++0x vector.data()????

M

Menace Denace

Hey guys, as i was just doing some small example programs i came
across an interesting feature apparently only available in the new
Microsoft Visual Studio 2010 Beta. The program is as follows

void p1()
{
cout<< "Reverse algorithm with STL containers.\n"<<endl;
vector<char> cvec = make< vector<char> >("This is a vector of
chars!");
cout<< "Size : " << cvec.size() <<endl;
reverse( cvec.begin(), cvec.end() );
cvec.push_back(0);
cout << cvec.data() <<endl;
cout<< "New Size : " << cvec.size() <<endl;
}

Id like to know why does this compile? vector does not have a data()
member as far as i know! is this some C++0x feature or just an
extension the Microsoft Compiler guys decided to add? Btw this code
will not compile on MSVC2008!
 
M

Menace Denace

Hey guys, as i was just doing some small example programs i came
across an interesting feature apparently only available in the new
Microsoft Visual Studio 2010 Beta. The program is as follows

void p1()
{
        cout<< "Reverse algorithm with STL containers.\n"<<endl;
        vector<char> cvec = make< vector<char> >("This is a vector of
chars!");
        cout<< "Size : " << cvec.size() <<endl;
        reverse( cvec.begin(), cvec.end() );
        cvec.push_back(0);
        cout << cvec.data() <<endl;
        cout<< "New Size : " << cvec.size() <<endl;

}

Id like to know why does this compile? vector does not have a data()
member as far as i know! is this some C++0x feature or just an
extension the Microsoft Compiler guys decided to add? Btw this code
will not compile on MSVC2008!

Forgot to add the make implementation, sorry

template < typename container >
container make ( const char s[])
{
return container( &s[0] , &s[strlen(s)] );
}
 
A

Alf P. Steinbach

* Menace Denace:
Yup.

As I recall C++0x unifies this access thing.

std::string got const and non-const versions of data too, IIRC.

or just an
extension the Microsoft Compiler guys decided to add? Btw this code
will not compile on MSVC2008!

Forgot to add the make implementation, sorry

template < typename container >
container make ( const char s[])
{
return container( &s[0] , &s[strlen(s)] );
}

You can let the second argument be just strlen( s ).


Cheers,

- Alf
 
A

Alf P. Steinbach

* Alf P. Steinbach:
* Menace Denace:
Yup.

As I recall C++0x unifies this access thing.

std::string got const and non-const versions of data too, IIRC.

or just an
extension the Microsoft Compiler guys decided to add? Btw this code
will not compile on MSVC2008!

Forgot to add the make implementation, sorry

template < typename container >
container make ( const char s[])
{
return container( &s[0] , &s[strlen(s)] );
}

You can let the second argument be just strlen( s ).

No, you can't.

I'm sorry, don't know exactly what I was thinking there.

There is a subtlety when the inferred argument type is an integral type, then
the first is treated as a count and the second as a value by §23.1.1/9, but
that's very different.


Cheers, & sorry for mis-information,

- Alf (self-correcting :) )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top