0

I was wondering if it is really worth it to include the type_traits header just to get the underlying type of an enum. I'm creating a Flags class that I want to be as flexible as possible so I'm using std::underlying_type<T>::type to get the type. I could use int for example but what if user wants to use more than 32 flags? So my question is, could it slow down compilation times anyhow significantly when used frequently?

4

1 回答 1

1

如果你需要 std::underlying_type 那么你需要它。编写自己的代码或损害您的代码是没有意义的。如果你想最小化编译时间,那么在头文件中前向声明模板类,并且只在 .cxx 文件中使用 type_traits.cxx ,这样你就不必在不同的文件中继承你不需要的头文件.

于 2012-11-16T15:53:10.567 回答