std::sort by unary mapping

The C++ standard library offers to pass a Comparator to std::sort. However, I have many cases in my code where I want to sort a list of T objects by a function f. A comparator like this would be a valid option: bool compare(const T& a, const T&a...
more »

2017-04-16 15:04 (2) Answers

Is move semantics in C++ something C is missing?

I have been searching for this matter on SO and other sources but I couldn't wrap my head around this issue. Using resouces of rvalues and xvalues somewhat new to C++ (with C++11). Now, do we - C programmers - miss something here? Or there is a cor...
more »

2017-04-07 07:04 (5) Answers

How use integer_sort from boost library?

I use boost::sort() from boost/range/algorithm.hpp but is really... slow and I'm just working with unsigned integer type, so I thought "Maybe using integer_sort() from boost/sort/spreadsort/integer_sort.hpp I can improve the speed" The Question is th...
more »

2017-04-01 09:04 (1) Answers

Correctly Writing a Range Based Constructor

I had a question to do with writing a range based constructor for a class but couldn't find the right phrasing to search for help on google. Suppose I am writing a simple class, like vector, which involves having a range based constructor that inser...
more »

2017-04-01 06:04 (1) Answers

Function not writing to txt file

I have a program that uses various structs and functions to read information into a struct from an output file, do something with it, and write to an output file if a condition is met. Everything is working properly, except the function that's suppos...
more »

2017-03-31 20:03 (1) Answers

Xcode, C++ and SFML. Library issues

I am trying to compile a simpel code that will show me a window by using Xcode with my mac. Everything seems to work and I get "Build Succeeded". But then nothing happens and I get the message: dyld: Library not loaded: @rpath/libsfml-audio.2.4.d...
more »

2017-03-30 15:03 (1) Answers

Input validation to only accept numbers

I'm creating program and it should only be allowed to accept numbers if a letter is entered it should re-ask the use to enter a number. When i run the code i get an error saying there's a problem with the break heres a copy of my code #include <...
more »

2017-03-30 08:03 (3) Answers

Cache locality with unique_ptr

I have a vector of custom classes (std::string just for example). The vector is large and I iterate through often, so I rely on cache locality. I also have one raw pointer which points at one of the vector elements. Now is the trick: The vector i...
more »

2017-03-29 22:03 (2) Answers

recursive function not called properly

I'm using a recursive method to convert a number into a representation in base of 7. However, after I run the program, the output string is identical to the input number. What's cause that the function is not called? #include <iostream> #inclu...
more »

2017-03-24 18:03 (1) Answers

Getting input as mm/dd and separating it

I've been working on a project. Where you get the input as: mm/dd as an example 12/30. But hey, there's the challenging part. I tried to use atoi and stoi... actually here's the code: Date::Date(const char* date){ string s; s = date; string delim...
more »

2017-03-19 16:03 (0) Answers

Time measurement via sleep () or usleep ()

I try to measure an exact time and have tried ... but with a "sleep (1) / usleep (1000)" I do not get what I expect. Here my test code and the result: unsigned long long start; unsigned long long end; // Example A: start = mach_absolute_time(); s...
more »

2017-03-06 01:03 (0) Answers

Static classes or instance pointers

Backstory: Currently I have a series of three classes related to a game. I've previously made games using Unity where you access components such as the camera using functions accessible throughout all code. My current setup, however, relies on insta...
more »

2017-02-28 12:02 (2) Answers

Is there a decltype equivalent in Swift?

In C++11 and latter, it is possible to use a compile time function like syntax named decltype() to reuse declaration type of a variable to declare another one without rewriting the type signature. Is there any equivalent syntactic tool in Swift? C++...
more »

2017-02-20 12:02 (1) Answers