我有一個派生自boost::variant<T, E>
的類型。我做了以下,我不能使用複製構造函數,我不明白爲什麼,一些SFINAE
似乎失敗。看起來boost::variant<T, E>
構造在繼承構造函數中將T
吞併爲ExpectedResult<T, E>
。 我怎樣才能解決它,使其工作和最簡單的解決方案?boost.variant派生類型:不能使用複製構造函數
template <class T, class E>
class ExpectedResult : boost::variant<T, E> {
public:
using boost::variant<T, E>::variant;
};
ExpectedResult<int,float> er;
ExpectedResult<int, float> er2 = er;
error: no type named 'type' in 'boost::enable_if<boost::mpl::and_<boost::mpl::not_<boost::is_same<Emotiv::Cortex::Utilities::ExpectedResult<int, float>, boost::variant<int, float> > >, boost::detail::variant::is_variant_constructible_from<const Emotiv::Cortex::Utilities::ExpectedResult<int, float> &, boost::mpl::l_item<mpl_::long_<2>, int, boost::mpl::l_item<mpl_::long_<1>, float, boost::mpl::l_end> > >, mpl_::bool_<true>, mpl_::bool_<true>, mpl_::bool_<true> >, void>'; 'enable_if' cannot be used to disable this declaration
typename boost::enable_if<mpl::and_<
^~~~~~~~~~
note: in instantiation of member function 'boost::variant<int, float>::variant' requested here
using boost::variant<T, E>::variant;
while substituting deduced template arguments into function template 'ExpectedResult' [with T = Emotiv::Cortex::Utilities::ExpectedResult<int, float>]
ExpectedResult<int, float> er2 = er;
守衛行爲是否應該被視爲一個錯誤?我發現所有必要的複製過度。也許我應該提交一個錯誤。 –
@GermánDiago該類型可能不是被設計爲繼承自;但他們可能會將某些is_same更改爲is_base_of,以便使其適用於您的情況。我不知道這是否會導致其他問題... – Yakk