function that takes only literal integers

后端 未结 3 1887
一生所求
一生所求 2021-01-03 22:30

I\'m looking for a way to simulate certain overloaded GCC built-ins in C++. The built-ins are similar to these:

__builtin_foo(char *a, signed int b);
__buil         


        
3条回答
  •  长发绾君心
    2021-01-03 23:00

    You could turn the function into a template:

    template 
    builtin_foo(char *a);
    

    The call syntax would then be builtin_foo<1>(whatever).

    If you don't like this, you could wrap the template in a macro:

    #define m_builtin_foo(a, b) builtin_foo<(b)>((a))
    

    This will of course accept any integral constant expression, not just a literal.

提交回复
热议问题