Lazy evaluation

前端 未结 1 1134
傲寒
傲寒 2021-02-06 00:10

How can I lazy evaluate second arg in std::conditional?

#include \"stdafx.h\"
#include 

struct Null{};
struct _1{enum {one = true,two = fal         


        
相关标签:
1条回答
  • 2021-02-06 00:36

    The usual technique for this is to have the std::conditional choose between two metafunctions:

    template <typename T>
    struct false_case {
      typedef typename std::conditional<T::one,_1,_2>::type type;
    };
    
    struct always_null {typedef Null type;};
    
    template<class T>
    struct X :
      std::conditional<is_nulltype<T>::value,
                       always_null,
                       false_case<T>
                      >::type::type { ... };
    

    Note the two ::types after std::conditional now.

    0 讨论(0)
提交回复
热议问题