Re: auto with array
On Thursday, May 5, 2011 5:51:18 PM UTC-4, SG wrote:
On 4 Mai, 22:13, Sarang wrote:
// too many initializers
auto arr2 = {'a','b','c'};
Weird. As far as I know, this is supposed to work and decltype(arr2)
is supposed to be std::initializer_list<char> in this case. Maybe it
has not yet been implemented in MSVC++.
$ cat main.cpp #include <algorithm>
#include <initializer_list>
#include <iostream>
#include <iterator>
int main() {
/* No problem in GCC 4.6.0. */
auto const cs = {'a', 'b', 'c'};
/* OK */
for (char const c : cs) {
std::cout << c;
}
std::cout << std::endl;
/* Also OK */
std::copy(cs.begin(), cs.end(), std::ostream_iterator<char>( std::cout ));
std::cout << std::endl;
}
$ make
/home/jeff/opt/gcc/bin/g++ -std=c++0x -pedantic -Wall -I. -Wno-unused-variable -Wno-unused-but-set-variable -o main.o -c main.cpp
../m/home/jeff/opt/gcc/bin/g++ -o main main.o
$ ./main
abc
abc
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]