std-function

    2熱度

    2回答

    This open-std document表明std :: function支持一個自定義分配器,但是我無法在互聯網上找到任何東西,或者找不到如何提供該自定義分配器的東西。 我的研究傾向於讓我相信自定義分配器是在boost::function中實現的,但是尚未達到std::function。 所以問題是std::function支持在C + + 11自定義分配器?如果不是,它最有可能支持C++

    14熱度

    2回答

    我目前有一個map<int, std::wstring>,但爲了靈活性,我希望能夠分配一個lambda表達式,並返回std::wstring作爲地圖中的值。 所以我創造了這個模板類: template <typename T> class ValueOrFunction { private: std::function<T()> m_func; public: Valu

    0熱度

    1回答

    #include <stdio.h> #include <functional> void foo(int a, int b) { printf("%d %d\n", a, b); } int main() { using namespace std::placeholders; auto f1 = std::bind(foo, 10, _1); //

    4熱度

    1回答

    我需要創建一個模板類,它可以保存指向T類型元素的指針,然後對它們執行函數。這些函數來自不同的地方,所以我需要一個容器來存儲它們,所以我可以稍後再調用它們。我決定使用std::unordered_set,因爲它提供了速度並限制了重複,因爲它被實現爲散列表。我寫了一整個類,但它不編譯,因爲沒有爲我的std::function定義的散列函數需要一個類型爲T的指針並返回void。使用struct hash

    1熱度

    1回答

    我有,我不能綁定此模板成員函數一個奇怪的問題, 所有這些代碼編譯:http://ideone.com/wl5hS8 這是一個簡單的代碼:我有一個ExecutionList應持有可調用的函數在std::vector。我現在可以通過調用ExecutionList::addFunctor來添加功能。但在那裏,我不能綁定到template<typename T> void Functor::calcula

    1熱度

    1回答

    我嘗試使用std ::函數,像這樣的成員函數: struct Foo { void bar(int) const { /* ... */ } }; //later on std::function<void(const Foo&, int)> fun = &Foo::bar; 這個工程下GCC 4.8.1,但無法在VS2013編譯如下錯誤: error C2664: 'vo

    1熱度

    1回答

    我試圖從另一個類中存儲第一個指針的類方法綁定,但它總是給我不同的值。 我在做什麼錯? 如果我按值傳遞類A(當然修改類B按值存儲)它是可行的。 #include <iostream> #include <functional> using namespace std; class A { public: A(double a, double b) : a(a), b(b) {}

    1熱度

    1回答

    我試圖使用一個帶狀態的lambda作爲函數指針參數,這裏的狀態表示它從它的上下文中捕獲。根據這個問題,這是不合法的:Why does the implicit "lambda to function pointer conversion" forbid the "by reference" capture of static members? 電流功能我想通過lambda來:void foo(vo

    0熱度

    2回答

    這是針對無效()函數子,但我都沒... struct Foo { void Bar(int x) { std::cout << x << std::endl; } }; struct VoidBind { typedef void result_type; template<typename T> void operator

    1熱度

    1回答

    我有非常使用的std ::的result_of,decltype和std ::功能 與可變參數模板的麻煩。 我有下面的函數功能 - int foo(int a, int b, int c) { std::cout << a << b << c << std::endl; return 0; } 及以下類 template <class T, class... Args>