Giter Club home page Giter Club logo

flexinvokable's Introduction

Flexible invokable for C++17

Single header container for lambdas with (or without) move-only encapsulation that can be invoked only once.

The topic of this repository is to address the need to store lambdas in containers (such as vectors). The generic way you are expected to do this is in std::function. However, std::function requires the encapsulated contents to be copy constructable. This is easy to imagine from the above struct: encapsulations sometimes cause issue! If you have members that are not copiable, then you cannot use std::function even though contents are movable. This is the need we are trying to address in flexInvokable. You can store your lambdas in move-only containers.

vah_CI CodeQL

Example

Example is shown in test/src/example.cpp.

How to use

Add flexInvokable/include/flexInvokable.hpp to your project.

Source

Originally found as an answer to the request in stackoverflow.

I had to make slight changes from source demo

void(*invoke)(void*, Args...) = nullptr; 

to

R(*invoke)(void*, Args...) = nullptr; 

Moreover,

std::result_of_t<std::decay_t<F>&(Args...)>

is getting deprecated, and therefore replaced to

#if _HAS_CXX17
    std::invoke_result_t<F, Args...>
#else
    std::result_of_t<std::decay_t<F>&(Args...)>
#endif

flexinvokable's People

Contributors

cihansari avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.