enable_if and conversion operator?

后端 未结 4 2056
天命终不由人
天命终不由人 2020-12-30 04:18

Any chance to use enable_if with a type conversion operator? Seems tricky, since both return type and parameters list are implicit.

4条回答
  •  执笔经年
    2020-12-30 05:03

    Actually, I have found a way; we use a private, unused class to mark a conversion that shouldn't exist, and we use boost::mpl::if_ to select whether to produce a conversion to NoConversion, or to the desired type.

    class A {
        class NoConversion { };
        template operator typename boost::mpl::if_::type() const;
    }
    

提交回复
热议问题