Will I be able to declare a constexpr lambda inside a template parameter?

后端 未结 2 558
旧巷少年郎
旧巷少年郎 2020-12-03 17:26

I know it\'s like opening the Pandora box but it doesn\'t stop bothering me. Consider a simple example:

#include 

template 
s         


        
2条回答
  •  萌比男神i
    2020-12-03 17:34

    In C++17 you can pass pointer to lambda function as template parameter with function pointer type:

    # include 
    
    template
    int get_twice()
    {
        return fn() * 2;
    }
    
    int main()
    {
        int result = get_twice <+[]() { return 42; }> ();
        assert(result == 84);
    }
    

提交回复
热议问题