有沒有辦法在編譯時打印constexpr或#define d值的值?我想的std::cout <<相當於或某種方式做這樣的事情 constexpr int PI_INT = 4;
static_assert(PI_INT == 3,
const_str_join("PI_INT must be 3, not ", const_int_to_str(PI_INT)));
編輯:
如果我在一個函數內部有一個變量(比如說一個大數組),那麼聲明它是否合理static和constexpr? constexpr保證數組是在編譯時創建的,那麼static就沒用了? void f() {
static constexpr int x [] = {
// a few thousand elements
};
// do something wit
常數初始化是什麼在以下方面的區別: #include <iostream>
using namespace std;
int get_value(int value){
return 3 * value;
}
int main(int argc, const char * argv[])
{
const int a = 5;
const int b
以下程序將調用樂趣 2 ^(MAXD + 1)次。儘管(如果我的想法是正確的話),最大遞歸深度不應該超過MAXD。因此編譯可能需要一些時間,但它不應該吃我的RAM。 #include<iostream>
const int MAXD = 20;
constexpr int fun(int x, int depth=0){
return depth == MAXD ? x : fu