Variadic template as parameters to std::function

I want to build a structure that allow me to call member functions with an undefined number of parameters. For now I wrote something like this template<typename Class, typename Return, typename ... Args> struct Caller { private: std::funct...
more »

2017-09-29 15:09 (2) Answers

Boost graph Library using Bundled properties

I am new to BGL and trying to setup a simple shortest path finding program using BGL where undirected graph is defined as a adjacency List with custom defined EdgeProperty and VertexProperty. I am getting compile time error which I attribute to my in...
more »

2017-09-23 13:09 (1) Answers

C++: Non-typed Function Pointer

How can I save a pointer to a function without save its return type? For example: int GetInt() { return 5; } string GetStr() { return "abc"; } FunctionPointerClass GetAny; int main() { GetAny = &GetInt; auto var = GetAny(); GetAny...
more »

2017-09-20 00:09 (2) Answers

C++ Class template type std::list

I have a thread safe queue class like below, Class CmdQ: template <typename Q> class CmdQ { public: CmdQ() : queue_(), queueMutex_(){}; ~CmdQ() { while (!queue_.empty()) { Q* element(std::move(this...
more »

2017-09-12 18:09 (2) Answers

Threads - Mac vs Linux

Great! I just finished my implementation on Mac with g++ / clang Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/M...
more »

2017-08-29 06:08 (1) Answers

C++ can't push class objects into std::vector

I thought i would be used to the usage of a vector. But somehow im getting problems while pushing class Objects into my std::vector. My vector is declared in my Class : Galaxy: //Galaxy.h #ifndef GALAXIS_H #define GALAXIS_H #include "Stern.h" #inc...
more »

2017-08-28 12:08 (0) Answers

Reusing variadic templates for constructors

How can one store a variadic template to enable reuse in later instances? Code Example: template <typename T, typename ...initArgs> Collection_class { std::vector<T> storage; initArgs ...constructorArguments; Collection_clas...
more »

2017-08-25 19:08 (2) Answers

c++ conditional generic class object

I have the following piece of code: helper.hpp : struct A { uint32_t a, b; }; struct B { uint32_t a, b; }; template <typename T> struct C { T barcode; }; Now based on some condition I want to create appropriate struct object in the...
more »

2017-07-01 21:07 (4) Answers

Sorting multiple vectors in single sort call C++

This answer demonstrates how to efficiently obtain an indices vector using std::sort on a vector of values using the nice new-ish C++11 functionality (there's also a variety of duplicates of that question as well). It also hints that you can obtain t...
more »

2017-06-30 23:06 (2) Answers

Combination of elements in an array returning sum

I am learning optimization problem using data structures. For that I have considered a problem in hand. I have an array like: movies[] = { 2,3,4,5,6,7,2,4,9 } I have a sum value: k = 5 Now I am finding the combination of array elements returning...
more »

2017-05-22 19:05 (1) Answers

Make a class that cannot be instantiated?

Suppose that I have a class Bar. I want to use Bar uniquely as a base class, e.g.: class Foo : public Bar I want to disallow Bar from being able to be instantiated. In other words, I want Bar object; to be an error. Is this possible to do? ...
more »

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

Passing a class member function to for_each

My question is: how do I pass a class member function into for_each Code I am trying to get to work: (works when function is defined outside of class) The part which fails is commented out - the one using for_each with function as the class member ...
more »

2017-05-09 23:05 (1) Answers