In a type trait, why do people use enum rather than static const for the value?

前端 未结 5 1861
别那么骄傲
别那么骄傲 2021-02-04 02:28

For example, this is how I would write it, and it compiles and works just fine:

template struct is_pointer {
  static const bool valu         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 03:08

    Is it only because the static const variable uses a byte of memory, whereas the enum doesn't?

    Yes, that's the reason.

    static const bool value = true;
    

    would occupy memory, while

    enum { value = true };
    

    doesn't.

提交回复
热议问题