g++4.8

Size of empty vector

半世苍凉 提交于 2019-12-04 18:50:17
The following program on running with g++ 4.8.2 gave the output 12 on a 32-bit Linux system: vector<char> v; cout << sizeof(v) << endl; I saw this and know that sizeof(v) could be implementation specific. Still, I was wondering what might be causing that vector to have a size of 12. What I think is that the iterators v.begin() and v.end() might be contributing to 8 bytes of the size. Am I correct? If yes, what is contributing to the remaining 4 bytes of size? If not, what are these 12 bytes all about? Take a look at the sources. libstdc++ is part of the gcc download. Anyway, the container must

C++ compiler does not recognize std::stringstream::swap

前提是你 提交于 2019-12-01 21:39:10
问题 I am trying to compile the following code with g++ (GCC) 4.8.2 20131212 (Red Hat 4.8.2-7): #include <sstream> using namespace std; int main(int argc, char ** argv) { auto x = 1; stringstream s1, s2; s1.swap(s2); } I get the following error: g++ -g -std=c++0x -c main.cpp main.cpp: In function ‘int main(int, char**)’: main.cpp:8:5: error: ‘std::stringstream’ has no member named ‘swap’ s1.swap(s2); ^ make: *** [main.o] Error 1 According to this reference it should work. Using different -std

Elaborated-type-specifier for a scoped enum must not use the ‘class’ keyword

不羁岁月 提交于 2019-12-01 14:56:00
I have the following enum specification: enum class FaceDirection : int8 { Down, Up }; g++ 4.8.1 gives the following error: warning: elaborated-type-specifier for a scoped enum must not use the ‘class’ keyword What causes this? Check the type you are deriving the enum class from exists. In this case, there was no typedef specified for int8 . 来源: https://stackoverflow.com/questions/20459120/elaborated-type-specifier-for-a-scoped-enum-must-not-use-the-class-keyword

Elaborated-type-specifier for a scoped enum must not use the ‘class’ keyword

送分小仙女□ 提交于 2019-12-01 13:41:10
问题 I have the following enum specification: enum class FaceDirection : int8 { Down, Up }; g++ 4.8.1 gives the following error: warning: elaborated-type-specifier for a scoped enum must not use the ‘class’ keyword What causes this? 回答1: Check the type you are deriving the enum class from exists. In this case, there was no typedef specified for int8 . 来源: https://stackoverflow.com/questions/20459120/elaborated-type-specifier-for-a-scoped-enum-must-not-use-the-class-keyword

When a C++ lambda expression has a lot of captures by reference, the size of the unnamed function object becomes large

混江龙づ霸主 提交于 2019-11-28 13:41:55
The following code: int main() { int a, b, c, d, e, f, g; auto func = [&](){cout << a << b << c << d << e << f << g << endl;}; cout << sizeof(func) << endl; return 0; } outputs 56 compiled with g++ 4.8.2 Since all local variables are stored in the same stack frame, remembering one pointer is sufficient to locate the addresses of all local variables. Why the lambda expression constructs a so big unnamed function object? I do not understand why you seem surprised. The C++ Standard gives a set of requirements, and every single implementation is free to pick any strategy that meets the

When a C++ lambda expression has a lot of captures by reference, the size of the unnamed function object becomes large

旧时模样 提交于 2019-11-27 07:48:45
问题 The following code: int main() { int a, b, c, d, e, f, g; auto func = [&](){cout << a << b << c << d << e << f << g << endl;}; cout << sizeof(func) << endl; return 0; } outputs 56 compiled with g++ 4.8.2 Since all local variables are stored in the same stack frame, remembering one pointer is sufficient to locate the addresses of all local variables. Why the lambda expression constructs a so big unnamed function object? 回答1: I do not understand why you seem surprised. The C++ Standard gives a

False positive with is_copy_constructible on vector<unique_ptr>

帅比萌擦擦* 提交于 2019-11-27 05:04:12
Should the type trait be able to handle cases such as std::vector < std::unique_ptr <int> > and detect that it's not copy constructible? Here's an example at https://ideone.com/gbcRUa (running g++ 4.8.1) #include <type_traits> #include <vector> #include <iostream> #include <memory> int main() { // This prints 1, implying that it's copy constructible, when it's clearly not std::cout << std::is_copy_constructible< std::vector<std::unique_ptr<int> > >::value << std::endl; return 0; } If this is the correct behavior for is_copy_constructible , is there a way to detect that the copy construction is

False positive with is_copy_constructible on vector<unique_ptr>

允我心安 提交于 2019-11-26 11:25:58
问题 Should the type trait be able to handle cases such as std::vector < std::unique_ptr <int> > and detect that it\'s not copy constructible? Here\'s an example at https://ideone.com/gbcRUa (running g++ 4.8.1) #include <type_traits> #include <vector> #include <iostream> #include <memory> int main() { // This prints 1, implying that it\'s copy constructible, when it\'s clearly not std::cout << std::is_copy_constructible< std::vector<std::unique_ptr<int> > >::value << std::endl; return 0; } If this