Conditionally disabling a copy constructor

后端 未结 6 1680
眼角桃花
眼角桃花 2020-12-08 04:34

Suppose I\'m writing a class template C that holds a T value, so C can be copyable only if T is copyabl

6条回答
  •  半阙折子戏
    2020-12-08 05:15

    template 
    class variant {
        struct moo {};
    public:
      variant(const variant& ) = default;
      variant(std::conditional_t::value,
                                 const variant&, moo>,
              moo=moo());
      variant() {};
    };
    

    This makes a non-eligible template instance have two copy constructors, which makes it not copy constructible.

提交回复
热议问题