Category "c++11"

How to run multiple threads in C++ code

I'm a beginner for c++. I wrote a program to extract data from one DB and store those data to another DB. I just want to add multiple threads to speed up the pr

Does auto deduce the type at compile time or runtime in C++ 11?

Consider the following auto a = 10; When does the compiler know that a is an int, at compile time or at run-time? If it deduces the type at run-time, will it n

Check if a given ostream object has been written to

Can I query an ostream object about whether or not it has been written to? For an ostringstream, one could use if(!myOssObject.str().empty()) What about the

Has the C++ standard committee considered templated namespaces?

Namespaces are in many was like classes with no constructors, no destructors, no inheritance, final, and only static methods and members. After all, this kind o

Can't use enum class as unordered_map key

I have a class containing an enum class. class Shader { public: enum class Type { Vertex = GL_VERTEX_SHADER, Geometry = GL_GEOMETRY_SHADE

Sum function with return type large enough to hold result

It's a question from C++ Primer Chapter 16.2.3 (question 16.41): Write a version of sum with a return type that is guaranteed to be large enough to hold t

is there a way to pass nested initializer lists in C++11 to construct a 2D matrix?

Imagine you have a simple matrix class template <typename T = double> class Matrix { T* data; size_t row, col; public: Matrix(size_t m, size_t n

When to use std::launch::deferred?

Lines from Anthony William book: std::launch::deferred indicates that the function call is to be deferred until either wait() or get() is called on the fu

What's the difference between constexpr and const?

What's the difference between constexpr and const? When can I use only one of them? When can I use both and how should I choose one?

const vs constexpr on variables

Is there a difference between the following definitions? const double PI = 3.141592653589793; constexpr double PI = 3.141592653589793; If not, which styl

initialize a vector to zeros C++/C++11

I know in C++11 they added the feature to initialize a variable to zero as such double number = {}; // number = 0 int data{}; // data = 0 Is there a simila

When is std::weak_ptr useful?

I started studying smart pointers of C++11 and I don't see any useful use of std::weak_ptr. Can someone tell me when std::weak_ptr is useful/necessary?

How do I activate C++ 11 in CMake?

When I try to run a CMake generated makefile to compile my program, I get the error that range based for loops are not supported in C++ 98 mode. I tried a

How do I activate C++ 11 in CMake?

When I try to run a CMake generated makefile to compile my program, I get the error that range based for loops are not supported in C++ 98 mode. I tried a

How is the UI of terminal texteditors implemented?

Terminal texteditors like emacs,vim,joe or even nano have the ability to display arbitrary UI elements inside a command line without completely rewriting the wh

How to get configuration.h from configuration.h.in in OpenSSL?

I am working with the OpenSSL library for C++. I used this library in another project and it worked great. I carried it over to another project today and I'm ha

How to check if a std::thread is still running?

How can I check if a std::thread is still running (in a platform independent way)? It lacks a timed_join() method and joinable() is not meant for that. I thoug

How to get on top-level const pointer using "auto"?

In short words: Per C++ Primer, pg 69, "auto": "If we want the deduced type to have a top-level const, we must say so explicitly". I would get an top-level

Can I list-initialize a vector of move-only type?

If I pass the following code through my GCC 4.7 snapshot, it tries to copy the unique_ptrs into the vector. #include <vector> #include <memory> in

How do I call ::std::make_shared on a class with only protected or private constructors?

I have this code that doesn't work, but I think the intent is clear: testmakeshared.cpp #include <memory> class A { public: static ::std::shared_pt