GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - niXman/overloaded: C++11 library allows to bind different callable into a single holder without any run-time overhead

BranchesTags
Open more actions menu

Latest commit

 

History

22 Commits
22 Commits

Folders and files

NameName
Last commit message
Last commit date
examples/overloaded-holder-as-arg
examples/overloaded-holder-as-arg
 
 
include
include
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
main.cpp
main.cpp
 
 
overloaded.pro
overloaded.pro
 
 

Repository files navigation

Overloaded

This C++11 library allows to bind different callable into a single holder without any run-time overhead.

Example

int add(int a, int b) { return a+b; }
double mul(double a, double b){ return a*b; }

auto func = overloaded::make(add, mul);

std::assert(func(2, 2) == 4);
std::assert(func(2.2, 2.2) == 4.84);

Overhead

For the following example:

/***************************************************************************/

__attribute__ ((noinline))
int f2(const int &v) {return v*2;}

__attribute__ ((noinline))
int f3(int &v) {v = v*2; return v;}

/***************************************************************************/

int main(int argc, char **) {
    int res = 0;
    auto *fp = &f2;
    auto overloaded = overloaded::make(fp, f3);
    res += overloaded(argc); // f3()
    res += overloaded(static_cast<const int &>(argc)); // f2()

    return res;
}

/***************************************************************************/

the following ASM will be generated:

f2(int const&):
        mov     eax, DWORD PTR [rdi]
        add     eax, eax
        ret
f3(int&):
        mov     eax, DWORD PTR [rdi]
        add     eax, eax
        mov     DWORD PTR [rdi], eax
        ret
main:
        sub     rsp, 8
        mov     DWORD PTR [rsp+4], edi
        lea     rdi, [rsp+4]
        call    f2(int const&)
        mov     edx, eax
        call    f3(int&)
        add     rsp, 8
        add     eax, edx
        ret

As you can see, there is nothing superfluous here!

About

C++11 library allows to bind different callable into a single holder without any run-time overhead

Topics

cppoverloaded-functions

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.