pointer as non-type template argument

后端 未结 2 825
青春惊慌失措
青春惊慌失措 2020-12-03 05:08

When answering this SO question, I found in the Standard (already C++03, still in C++11) that you can only use addresses as non-type template arguments if they\'re of the fo

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 05:30

    1. It cannot be a variable, since variables are only set at runtime.
    2. It cannot be a constexpr, since the value of an address cannot be known at compile time; in most cases it will only be fixed after relocation prior to execution.
    3. It might theoretically be an arithmetic expression (even though it isn't allowed in the standard), but in the common case of an address of an array element, you can simply use &arr[i] instead of arr + i.

提交回复
热议问题