sfinae

    3熱度

    3回答

    我想寫一個智能指針包裝(包含一個boost shared_ptr或scoped_ptr或另一個智能指針包裝);每個包裝類型都會注入一些額外的功能(例如,日誌記錄的使用,懶惰的初始化,驗證正確的構造/銷燬順序等),但是我希望它們對用戶儘可能隱形(這樣我就可以交換進/出包裝只需更改一個typedef,可能還有一些構造函數代碼,但不包含使用代碼)。 正常使用很簡單: template<typename

    6熱度

    1回答

    我試圖寫這樣的非成員運算符函數模板: #include <utility> template < typename T, unsigned L > class MyType; template < typename T, typename U, unsigned L > auto operator ==(MyType<T,L> const &l, MyType<U,L> const &

    2熱度

    1回答

    我不確定這與sfinae有什麼關係,或者只是與任何模板函數相關的東西。我試圖使用SFINAE基於相應的遊離功能,這又基於在另一種類型的成員函數的所有腦幹使能/禁止的存在以啓用/禁用一個成員函數,所有使用方法描述here: struct S; template <typename T> inline auto f(S& s, T const& t) -> decltype(t.f(s

    4熱度

    3回答

    如何測試函子是否是一個可調用的對象,它接受對int的引用並返回一個bool? template<typename functor> void foo(functor f) { static_assert('functor == bool (int&)', "error message"); int x = -1; if (f(x)) std::cou

    1熱度

    1回答

    我有這些簽名一dotProduct方法: template<typename It, typename It2> typename DetermineResultType< typename std::iterator_traits<It>::value_type, typename std::iterator_traits<It2>::value_type>::Result dotProduc

    2熱度

    3回答

    用戶通過定義指定所需選項的類來定製庫模板類。稱之爲清單。這個想法是在清單中有可選的typedef。例如,如果用戶的清單包含H的typedef,我希望庫代碼使用指定的類型作爲其「H」。如果用戶清單中沒有typedef,庫將使用默認值。 我懷疑有一個優雅的方式來利用新的C++ 11功能來做到這一點,但我現在空了。我有一個解決方案,基於SFINAE的維基百科條目。這是醜陋的。它需要一個新的模板功能has

    4熱度

    1回答

    我有一堆類似COM的集合接口,我試圖編寫類似STL的迭代器。我有迭代器的工作,並專門begin()和end()返回我的迭代器。一切都完美無缺!除了當我嘗試使用begin(std::vector)時,它使用我非常普遍的begin()專業化。由於這些COM對象不從基集合對象擴展,我第一次嘗試: template< class CollType > CollectionIterator<CollTyp

    4熱度

    3回答

    這裏是我有些奇怪的代碼: template <typename T&> class A { public: void b(typename std::enable_if<!std::is_pointer<T>::value, T>;::type o) {} void b(typename std::enable_if<std::is_pointer<T>::value, T

    5熱度

    1回答

    我有這樣的成員函數測試: template <typename T> struct has_member { template <typename U> static true_type f(decltype(declval<U>().member()) *); template <typename> static false_type f(...); static

    8熱度

    3回答

    我有一個SFINAE問題: 在下面的代碼,我想C++編譯器挑專門仿函數和打印「特殊」,但它打印「一般「而是。 #include <iostream> #include <vector> template<class T, class V = void> struct Functor { void operator()() const { std::cerr << "ge