constexpr function parameters as template arguments

前端 未结 4 1130
谎友^
谎友^ 2020-11-30 07:43

I am playing around with some toy code using c++11 to figure out a bit more about how things work. During this I came across the following issue that simplifies down to:

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 08:07

    If your purpose is just to shorten code a bit, in C++14 you can create variable template:

    template 
    constexpr int addVar = x + y;
    
    cout << addVar<5, 6> << endl; // Works with clang 3.5, fails on GCC 4.9.1
    

    GCC 5 will also support this.

提交回复
热议问题