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

Distribution as member of class in C++

I have two related questions concerning the use of distributions inside classes. Is there some kind of base distribution in C++ in order to use a distribution as a class member without knowing which distribution it will be? I cannot use templates (...
more »

2017-02-13 13:02 (2) Answers

C++ Function Syntax

In this example, #include "crow.h" int main(){ crow::SimpleApp app; CROW_ROUTE(app, "/")([](){ return "Hello world"; }); app.port(18080).multithreaded().run(); } What does this snippet ([](){ refer to ? I cannot seem to find any refer...
more »

2017-02-09 01:02 (0) Answers

C++ Invalid Comparator sorting Vector of Structs

I'm trying to Sort a std::vector containing custom structures, each of which has its own vector of int values. The key is that I want to sort based on the ordering of the internal int vector... i.e. {1, 1, 2, 3, 4} is less than {1, 2, 2, 3, 4} becau...
more »

2017-02-05 15:02 (1) Answers

Set template argument in other class in C++

Is there a way to set the template argument of a template class inside another class? I want to have a class that generates a distribution of a certain type (normal, uniform etc.) with two values. The class should be called like this: Dist normal("n...
more »

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

NDK ambiguous 'log' error with c++_static

I'am building my cpp library using CMake and gradle on Android with Android Studio 2.2.3. I'am using c++_static as STL but I always obtain these errors: error: reference to 'log' is ambiguous log(_A1 __lcpp_x) _NOEXCEPT {return log((double)__lcpp_x)...
more »

2017-01-24 20:01 (0) Answers

Selectively sort vector c++

I have the following vector: vector<unsigned> vec = {5, 6, 5, 4, 1, 3, 0, 4} Now I want to sort this vector lexicographically by odd indices (and if odd indices are equal, then by the even indices). Such that the sorted vector "vec" is: ...
more »

2017-01-24 14:01 (4) Answers

iOS Clang -std -stdlib options c++11 error

I have an iOS project set up like this: I use XCode 6.1.1 clang -v says LLVM version 6.0 I use the flag -miphoneos-version-min=6.1 (I don't set -std and -stdlib) Everything's fine. When I update to -miphoneos-version-min=7.1 I have following err...
more »

2017-01-16 17:01 (0) Answers

C++ sort with 'tweaked' compare functor

I have a class functor (too complex to implement as a lambda), but to strip the idea down, I want to ensure the functor satisfies the Compare predicate. The issue is, I want all values larger than (1) to yield ascending order, but to place all values...
more »

2017-01-07 05:01 (1) Answers

Binding generic callbacks with arguments c++11

I have a class called Renderer that holds two callback objects; void (*drawCall)(const sf::Drawable& drawable, const sf::RenderStates& states); void (*drawPrimCall)(const sf::Vertex* vertices, unsigned int vertexCount, sf::PrimitiveType ...
more »

2017-01-06 14:01 (2) Answers

std::sort algorithms memory usage

I'm wondering whether the standard libraries sorting algorithms (e.g. std::sort) are using the heap memory for sorting. Is there any reliable source how to find out what kind (heap, stack) and how much of temporary memory is used by a sorting algor...
more »

2017-01-05 00:01 (1) Answers

Class Template Errors , Linked Lists

I am trying to create an unordered Linked List and the textbook that I am using says that a linked list iterator class is needed before creating the linked list ADT. Ultimately it will be a functional linked list that can print in reverse, split at a...
more »

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

Using too many functions

I'm reading a book in which a window class' constructor doesn't initialize all the implementation directly, instead it calls a function that calls another etc... e.g. window::window(T&t, X&x) { setup(t, x);} void window::setup(T&t, X&a...
more »

2017-01-03 16:01 (2) Answers