Category "c++11"

Why isn't abs constexpr?

In <cinttypes>, since C++11, there are the following two overloads: std::intmax_t abs( std::intmax_t n ); std::intmax_t imaxabs( std::intmax_t n ); Why

When does instantiation happens for explicit instantiation of a function template

Hi i am learning about explicit instantiation. And so reading different examples but in one example have some doubts. The example is given below and i have 2 do

The implementation of std::forward

I'm reading Overview of the New C++ (C++11/14) (PDF only), at Slide 288 it gives an implementation of std::forward: template<typename T> //

Is it possible to use std::string in a constexpr?

Using C++11, Ubuntu 14.04, GCC default toolchain. This code fails: constexpr std::string constString = "constString"; error: the type ‘const string

What is the proper use of CMake FindThreads with modern C++?

The source for the CMake (https://github.com/Kitware/CMake/blob/master/Modules/FindThreads.cmake) claims the following about the "FindThreads" functionality:

What is the difference between std::reference_wrapper and a simple pointer?

Why is there a need to have std::reference_wrapper? Where should it be used? How is it different from a simple pointer? How its performance compares to a simple

How to move elements from a set to a vector efficiently?

I have a std::set<vector<int>> from which I would like to move (not copy) elements to a std::vector<vector<int>>. How do I do this? I t

Move-only version of std::function

Because std::function is copyable, the standard requires that callables used to construct it also be copyable: n337 (20.8.11.2.1) template<class F> funct

How does #include <bits/stdc++.h> work in C++? [duplicate]

I have read from a codeforces blog that if we add #include <bits/stdc++.h> in a C++ program then there is no need to include any other h

Algorithm to convert std::stack to std::string in C++ STL

In below C++ program I'm deleting a previous character considering '#' as a backspace character. I have used stack to build the string. Is there any C++ STL alg

‘is_trivially_copyable’ is not a member of ‘std’

My gcc version is 4.8.3 20140624. I can use is_pod, is_trivial, is_standard_layout, but fail when trying is_trivially_copyable, is_constructible and is_default_

Why the boost msm calls the guard twice?

I'm implementing a state machine as the following diagram state machine diagram I trigger "event1" and "event2" to the state machine, when "event1" triggered,

How to initialize `std::function` with a member-function?

I am trying to learn std::function and here's my code: #include <iostream> #include <functional> struct Foo { void print_add(int i){ st

error: call to implicitly-deleted copy constructor of 'std::__1::unique_ptr<A, std::__1::default_delete<A> >'

I'm constructing an object that takes a std::vector<std::unique_ptr<A> > as an argument. The constructor is defined like this class B { std::ve

Emplace back thread on vector

Why this cause undefined behavior? #include <iostream> #include <thread> #include <vector> std::vector<std::thread> threads(3); void

how to access only element of unordered_set in c++?

For ex, unordered_set<int> s ; s.insert(100); How do I get value 100 from s? From http://www.cplusplus.com/reference/unordered_set/unordered_set/begin

What is the purpose of std::function, and how to use it?

It is necessary to me to use std::function but I don't know what the following syntax means. std::function<void()> f_name = []() { FNAME(); }; What is

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