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

C++ sort cannot sort set of strings?

I am wondering how I can sort a set that contains strings. For example, I have a set: std::set<std::string> setA = {"B","A","C"} Then I wanna use this to do the sorting: std::sort(setA.begin(),setA.end()); But the C++ compiler cannot let ...
more »

2017-01-01 17:01 (3) Answers

Difference between f and &f

Consider the code: void f(int) {} int main() { std::function<void(int)>func = f; func(3); std::function<void(int)>funcc = &f; funcc(3); void(*ptr)(int) = f; ptr(3); void(*ptrr)(int) = &f; ptrr(3)...
more »

2016-12-25 10:12 (0) Answers

How to make qtcreator work with c++11

I am trying to make school project works locally, but I keep having trouble with qtcreator and c++11. The compilator keeps saying it can't use c++11 stuffs: /Users/yoong93/Qt5.6.2/5.6/clang_64/lib/QtCore.framework/Headers/qstring.h: 757: error: no ...
more »

2016-12-24 09:12 (1) Answers