Category : functional-programming

I am trying to call a function using a std::map key value pair. I found this stackoverflow article Calling a function depending on a variable? but the solution std::map<std::string, std::function<void()>> le_mapo; does not work and results in a error something like "error: lvalue required as unary ‘&’ operand" using it as so std::map<std::string, std::function<void()>> le_mapo; ..

Read more

#include <functional> bool f1(int a, int b) { return true; } int main() { // This compiles std::function<bool()> f2 = std::function<bool()>(std::bind(f1, 1, 2)); std::function<bool()> f1 = f2; // These don’t compile //std::function<bool()> f1 = std::function<bool()>(std::bind(f1, 1, 2)); //std::function<bool()> f1 = std::bind(f1, 1, 2); //std::function<bool()> f1(std::bind(f1, 1, 2)); } I was trying to overload f1 by ..

Read more

#include <functional> bool f1(int a, int b) { return true; } int main() { // This compiles std::function<bool()> f2 = std::function<bool()>(std::bind(f1, 1, 2)); std::function<bool()> f1 = f2; // These don’t compile //std::function<bool()> f1 = std::function<bool()>(std::bind(f1, 1, 2)); //std::function<bool()> f1 = std::bind(f1, 1, 2); //std::function<bool()> f1(std::bind(f1, 1, 2)); } I was trying to overload f1 by ..

Read more

tl;dr I’d like to understand what’s wrong with the first code below, i.e. what the error is telling me. Full question I’m having trouble understanding the errors I get when I try partially applying std::visit to a visitor function obtained via boost::hana::overload. (I know that I can’t pass around the name of a template function, ..

Read more

I have a vector: std::vector<int> v; I push back 10 elements to this vector so now it has 10 elements: v[0], v[1], … ,v[9] I have another vector: std::vector<std::function<>()> v5; I want to push_back() these formulas to v5: v[0]*v[1], v[0]*v[2], … How can I push_back() these formulas to v5 vector? Can you help me for ..

Read more

My question I’m referring to a function which does essentially the following (modulo const, &, perfect forwarding, or whatever is appropriate): auto constexpr dollar = [](auto f, auto x){ return f(x); }; // Why calling it "dollar"? Keep reading… Is such a function expressable only via Boost.Hana? Why did I think of it? In Haskell, ..

Read more

I want to do this: bool hasDisconnect(std::map<int, IOConnection> io_connections) for(auto const&[connection_number, io_connection] : io_connections) { if (io_connection->checkIfDisconnect()) { return true; } } return false; } But with any_of like this: std::any_of(io_connections, [](auto const&[connection_number, io_connection]]){ io_connection->checkIfDisconnect() }); Is this possible in c++ 17 (preferred) or c++20? Source: Windows Que..

Read more