std-function

    9熱度

    7回答

    我有許多具有不同簽名的回調函數。理想情況下,我希望將這些放入矢量中,並根據特定條件調用適當的函數。 例如 void func1(const std::string& value); void func2(const std::string& value, int min, int max); const std::vector<std::function<void(std::string)

    1熱度

    1回答

    請有人幫助解釋爲什麼在OS X上使用Xcode 5.1編譯以下代碼時出現錯誤。 Apple LLVM 5.1版(clang-503.0.40)(基於在LLVM 3.4svn上)。 #include <vector> #include <functional> void func1(const std::string& value) { // ... } void func2

    3熱度

    2回答

    下面的函數重載是不明確的。我發現std::function可以constructed from most callable types,即使他們的簽名不匹配。所以編譯器無法知道要使用哪個函數。 template <typename T> void each(std::function<void(T)> iterator); template <typename T> void each(std:

    12熱度

    3回答

    首先,我定義了兩個相互繼承的類。 class A { }; class B : public A { }; 然後,我宣佈一個使用std::function<void(A*)>功能: void useCallback(std::function<void(A*)> myCallback); 最後,我收到的std::function不同的(但理論上兼容)從別的地方,我想打字在我的回調函數中使

    2熱度

    1回答

    我寫了一個模板類有一個無參數的空隙返回函數對象的工作: //...Class declaration here... template<class FunctionObject> Alarm<FunctionObject>::Alarm(const FunctionObject& fn) : StopWatch(), _delegate(fn), _tickTime(1.0), _

    0熱度

    1回答

    我通常從不寫C++,而今天我嘗試過使用C++模板進行實驗。我實現了一個也許鍵入它看起來像這樣 #include <functional> #include <iostream> #include <string> template<typename T> class TMaybe { T value; public: TMaybe() : value(nullptr

    1熱度

    2回答

    我們有一個函數將一個函數對象作爲參數。函數有兩個重載,它們在函數簽名中有所不同。 #include <functional> template <typename T> void foo(std::function<void(T)> bar) { } template <typename T> void foo(std::function<void(int, T)> bar)

    0熱度

    1回答

    我使用匿名函數(也稱爲lambda)作爲find_if的條件。顯然我可以爲它製作一個特殊的類,但是C++ 11說我可以使用匿名函數。 但是,爲了便於閱讀和理解,我決定將匿名函數保存在作爲函數鍵入的局部變量中。 不幸的是,我得到的錯誤: no match for call to '(std::function<bool(Point*, Point*)>) (Point*&)' note: cand

    0熱度

    1回答

    我有一堆委託工廠,使用不同的參數定義爲lambda表達式,即: std::function<Mesh*()> f1 = [&]() -> Mesh * {return new Mesh();}; std::function<Image*(const std::string&)> f2 = [&](const std::string& path) -> Image * {return new Im

    0熱度

    1回答

    我想創建一個可調用元素的狀態隊列,因此我可以存儲可調用元素(帶有一個整數,指示應該何時調用它),然後再調用它(在檢查其中存儲的整數之後)。 我一直在閱讀過去幾天的函數和std :: function模板,我想知道下面兩個選項中哪一個在內存和性能方面會更好(哪個更好,如果不同)。 第一種選擇: class UpdateFunction : public std::function<bool(unsi