Set all bytes of int to (unsigned char)0, guaranteed to represent zero?

C++ 11 I think the pertinent part are 3.9.1/1 In C++11 For character types, all bits of the object representation participate in the value representation. For unsigned character types, all possible bit patterns of the value representation represent numbers. These requirements do not hold for other types. Along with 3.9.1/7 The representations of integral types … Read more

C++11: How to set seed using

The point of having a seed_seq is to increase the entropy of the generated sequence. If you have a random_device on your system, initializing with multiple numbers from that random device may arguably do that. On a system that has a pseudo-random number generator I don’t think there is an increase in randomness, i.e. generated … Read more

Perfect forwarding – what’s it all about? [duplicate] Why is this useful? Well, it means that a function template can pass its arguments through to another function whilst retaining the lvalue/rvalue nature of the function arguments by using std::forward. This is called “perfect forwarding”, avoids excessive copying, and avoids the template author having to write multiple overloads for lvalue and rvalue references.

Default initialization of std::array?

By definition, default initialization is the initialization that occurs when no other initialization is specified; the C++ language guarantees you that any object for which you do not provide an explicit initializer will be default initialized (C++11 §8.5/11). That includes objects of type std::array<T, N> and T[N]. Be aware that there are types for which … Read more

When is std::weak_ptr useful?

std::weak_ptr is a very good way to solve the dangling pointer problem. By just using raw pointers it is impossible to know if the referenced data has been deallocated or not. Instead, by letting a std::shared_ptr manage the data, and supplying std::weak_ptr to users of the data, the users can check validity of the data … Read more

How do I enable C++11 in gcc?

H2CO3 is right, you can use a makefile with the CXXFLAGS set with -std=c++11 A makefile is a simple text file with instructions about how to compile your program. Create a new file named Makefile (with a capital M). To automatically compile your code just type the make command in a terminal. You may have … Read more

Why does C++11 not support designated initializer lists as C99? [closed]

On July 15 ’17 P0329R4 was accepted into the c++20 standard: This brings limited support for c99‘s Designated Initializers. This limitation is described as follows by C.1.7[diff.decl].4, given: struct A { int x, y; }; struct B { struct A a; }; The following Designated Initializations, which are valid in C, are restricted in … Read more

How do I activate C++ 11 in CMake?

CMake 3.1 introduced the CMAKE_CXX_STANDARD variable that you can use. If you know that you will always have CMake 3.1 or later available, you can just write this in your top-level CMakeLists.txt file, or put it right before any new target is defined: set (CMAKE_CXX_STANDARD 11) If you need to support older versions of CMake, … Read more