Can not insert a character into a string

So basically my function goes through every character in a string and inserts each character onto another string so it results in the initial string being reversed. I've looked up online but the answers to this problem seem to not work anymore, I'm n

Is the std :: exception_ptr thread secure?

I have a worker thread that is constantly running, created & managed through a std::thread. At the top level of my worker thread, I have a try/catch block with a while loop inside it. If an exception leaks through to the top level of the thread, I ca

Define the function / method if it is not defined before c ++

I don't use C++11 yet, so I wrote the functions to_string(whatever) by myself. They should only be compiled if they don't exist. If I switch to C++11, they should be skipped. I have something like this: #ifndef to_string string to_string(int a){ stri

Functional composition with various models

My goal is to get composition of functions working with this exact syntax: int main() { Function<std::string, int> f([](const std::string& s) {return s.length();}); Function<int, double> g([](int x) {return x + 0.5;}); Function<double,

Descending table for the decimal factor

Is there efficient way to downscale number of elements in array by decimal factor? I want to downsize elements from one array by certain factor. Example: If I have 10 elements and need to scale down by factor 2. 1 2 3 4 5 6 7 8 9 10 scaled to 1.5 3.5

How to join a std :: thread from itself (in C ++ 11)

I have a std::thread waiting and reading from a socket. And there is a pointer to this thread stored somewhere. But when something bad happens and the thread ends, I want it to call something that results in a function that will join this thread and

How to create a packaged_task with a member function?

On the program below, I'm trying to create a packaged_task with a member function: #include <future> using namespace std; struct S { int calc(int& a) { return a*a; } }; int main() { S s; auto bnd = std::bind(&S::calc, s); std::packaged_task&

Check the traits for all arguments of the variadic model

Background : I've created the following class C, whose constructor should take N variables of type B& : class A; class B { A* getA(); }; template<size_t N> class C { public: template<typename... Args> inline C(Args&... args) : member{a

Is it possible to read a file at compile time?

I am wondering if it is possible in C++11/14 to actually read files at compile time. For example the following code will only compile if it can successfully read the file. constexpr std::string shader_source = load("~/foo.glsl"); Do you think th

unordered_map with an IP address as key

I am trying to build a list of linked list in my application. The list will contains unique IP addresses,and for each IP addres I have a list of applications. I am trying to build it using unordered_map to take Boost::boost::asio::ip::address as a th

Transfer to an on-site builder

I have a message class which was previously a bit of a pain to work with, you had to construct the message class, tell it to allocate space for your object and then populate the space either by construction or memberwise. I want to make it possible t

Inheritance of a virtual function

I have the following piece of code. class A { public: virtual void foo() = 0; } class B : public A { public: void bar() { /* Do something */ } } void B::A::foo() { bar(); // Do something else } When I try to compile this... I get an error saying it c

C + + 11 move and reassign

This code does compile but I'm just beginning studying C++11 and I can't understand what's happening here behind the scenes. void func(int&& var) { int var2(var); } void main() { int var1 = 22; func(move(var1)); } My guess: move(var1) returns a r-

Execute a member function of a class

I am trying to experiment the C++11 threads in a way that it accepts a member function of a class as a parameter into the thread constructor as shown in the first code snippet below on line 20 that is marked . The class definition is given in the 2nd

The best way to declare an interface in C ++ 11

As we all know, some languages have the notion of interfaces. This is Java: public interface Testable { void test(); } How can I achieve this in C++ (or C++11) in most compact way and with little code noise? I'd appreciate a solution that wouldn't ne

C ++ 11 lambda discomfort

Any ideas why the following code segfaults? class foo represents any class. This seams like a good idea for providing an evented interface. #include <iostream> #include <functional> class foo { public: foo() { val = 42; }; void bar(std::functi

Manipulation of variadic models in c ++ 11

I have recently started using C++11, and I have read in a tutorial about variadic templates. I have understood that we can define a variadic template like this // example class that uses variadic template template<typename ...Args> struct mtuple; Bu

QT Creator, syntax check for c ++ 11

How to turn off error highlighting (red wave under the code) for c++11 cycle range-based operators like that? int myint[] = {1,2,3,4,5}; for (auto x : myint){/**/} Hover prompt shows "unexpected token :". The code compiles perfectly. Another iss

& ldquo; id & rdquo; Works in C ++ 0x

Reading this answer regarding returning rvalue references from function got me thinking, how can I write an id function in C++0x. Basically, I want id to be a do nothing function, a function that has no observable effects on the program. My first att

Boost - tutorial unordered_set / examples / NOTHING?

I'd like to use unordered_set in a project. However, documentation for it is either incomplete or just a technical reference, no examples. Can anyone provide links to online resources which deal with it? Books also welcome, preferably free. Google se

Does C ++ 11 provide hash functions for std :: type_info?

I'm still working on a good solution to my One-Of-A-Type Container Problem -- and upon reflection I think it would be nice to be able to just use something like a std::map<std::type_info, boost::any>. Unfortunately, std::type_info does not define an