为什么要枚举而不是静态bool? [英] Why enum instead of static bool?

查看:76
本文介绍了为什么要枚举而不是静态bool?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在模板元编程中使用枚举而不是静态const bool是更好的做法?

我读过亚历山大的书中的某处,但找不到它,真的想知道它。 p>

Why is it considered better practice to use enum not static const bool in template metaprogramming?
I've read that somewhere in Alexandrescu's book but cannot find it and really would like to know it.

推荐答案

关键原因是,一个静态bool是一个变量,枚举是一个类型 - 因此在枚举没有变量

The key reason is that a static bool is a variable after all and a enum is a type - hence in case of enum no variable is ever instantiated and it's thus guaranteed to be a compile-time evaluation.

另请参阅此问题了解详情。

这篇关于为什么要枚举而不是静态bool?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆