![](/img/trans.png)
[英]std::function and default function arguments
這是使用std::function的簡單示例 在主function中,有3個function呼叫。 第一個和最后一個有效。 而沒有任何 arguments 的第二次調用testFunc()給出了編譯時錯誤。 不應該考慮默認的arguments,執行成功嗎? ...
[英]std::function and default function arguments
這是使用std::function的簡單示例 在主function中,有3個function呼叫。 第一個和最后一個有效。 而沒有任何 arguments 的第二次調用testFunc()給出了編譯時錯誤。 不應該考慮默認的arguments,執行成功嗎? ...
[英]what is the difference between operators associativity and order of evaluation in c++
運算符的結合性和求值順序有什么區別? 我期望運算符關聯性是同一組中具有相同優先級的運算符的優先級,但我無法理解運算符關聯性和評估順序之間的區別 ...
[英]Expand template type
有沒有辦法將每種類型的 std::tuple 轉換為特定的子類型? 我有以下代碼 有沒有辦法將 myTypes 轉換為以下類型? 類型的順序無關緊要,但是像上面那樣使用它會很好。 ...
[英]How to make the indentifier "tortuga" not to be undefined?
我想創建這個 function: 但是,我知道標識符“tortuga”未定義。 我試圖像這樣修改 function: 我知道現在定義了標識符“tortuga”,這似乎有效。但是,20ish windows 出現在每個 window 中,烏龜只畫了一個正方形的三個邊,如下圖所示: image我希望繪 ...
[英]Is it possible to have static constexpr fields in a private inner class?
我有一個 C++14 項目,不能使用 C++17 內聯變量。 是否有可能讓它在 C++14 中工作,或者這只能在 C++17 中工作? ...
[英]C++ condition variable wait, does the wait block if the predicate is already true?
這里我是Writer工作線程,想知道Reader主線程是否已經到了PrepDone state。 下面我是讀者,我想知道 Writer 是否達到了 WriteDone。 很明顯,觀察到類似掛起的情況,就像每個人都在等待另一個人,並且都沒有調用各自的 notify_one()。 感謝任何反饋謝謝。 ...
[英]Reference mocked class
我的代碼結構如下 我想為此創建一個 gtest 模擬,但我遇到了一個問題...... 我如何實現這樣的模擬? 如果我向上轉型,它不會只調用該方法的非模擬版本嗎? ...
[英]Calling overloading template function by func(1) and func<int>(1) leads to difference result
我有兩個模板函數: 而調用func不同的方法會導致不同的結果: 這是演示。 我原本認為func(1)和func<int>(1)是相同的,但看來我錯了。 編譯器是否以不同方式對待func(1)和func<int>(1) ? 謝謝你的幫助! ...
[英]Why thread keeps hanging during condition_variable.wait()
我正在嘗試編寫一個使用線程的程序。 線程應該休眠並等待 Stack 的頭指針改變,然后做一些事情並再次休眠。 但是,我的線程一直掛在等待 function 上,我的程序也隨之掛起,等待語句更改。 但它不會,因為整個程序都在等待線程完成。 所以..這是我的代碼,它正在工作,當我將線程連接放入析構函數時 ...
[英]Does a constant reference member variable in an anonymous struct extend the lifetime of a temporary?
考慮以下代碼: 因此GetTemp()返回一個臨時值 object,然后將其分配給常量引用變量。 但是,該常量引用變量是匿名局部結構的成員。 問題:C++ 標准是否保證臨時對象的生命周期會延長到循環終止之后? 考慮到這個問題,我本以為答案是否定的,即我在循環體中得到了一個懸空引用。 然而, gcc ...
[英]How the intelisense for std::make_shared() know the default constructor arguments? Is it Visual Studio or C++? If C++, how can I implement it myself
std::make_shared()用於直接構造一個 object 作為shared_ptr並調用給定類型的構造函數,它采用該類型構造函數的 arguments。 它如何知道 arguments 和類型構造函數的定義? 當使用模板和...運算符時,visual studio intellisens ...
[英]How to call one of two C++ template functions with condition
有一個class,有兩個成員模板函數:fun1()、fun2()。 我想調用由 const bool class 成員決定的函數之一:willCallFun1。 代碼中有類似 fun() 的解決方案,但是 if-else 分支會在每次調用 fun() 時檢查。 我想避免分支。 由於構造Foo obj ...
[英]Why do unique_ptr have two functions reset and operator= that do similar things but not overload?
我知道這聽起來像是一個奇怪的問題,但我很好奇。 unique_ptr operator= 將右值引用作為參數並調用 reset(r.release()),然后移動自定義刪除器。 最后,運算符返回 *this。 喜歡: unique_ptr reset function 以左值原始指針為參數,在 ...
[英]C++ template to check if input type implements `operator []`
我正在嘗試使用模板來檢查輸入類型是否實現了operator[] 。 這是我的代碼: 但它沒有用。 無論我輸入哪種類型,它總是 output 0。 我認為如果T = int或T = double , decltype(&T::operator[])將失敗並且將根據 SFINAE 使用主要的h ...
[英]std::thread dosnt dosnt excute funtion c++
我有這個簡單的 function: 現在當我嘗試運行它時: 只有從主 class 打印的開始,它永遠不會到達 function(); 在 setInterval function 中,它只是停止應用程序而沒有錯誤。 編譯/鏈接命令: ...
[英]Overloading operator>> to create array from string
我想從std::string創建一個std::array 。 為此,我想重載operator>> 。 我有以下測試用例: 我想讓操作員檢查字符[和]是否在正確的位置,並用里面的元素構造數組。 如何檢查提取是否成功? 如何檢查括號之間的字符串是否為數字,如果是,如何從中構造我的數組? 親切 ...
[英]How to pass a template type (std::array or std::vector) to a template parameter
我有一個 function 模板,其中 function 的返回類型是模板參數。 根據https://en.cppreference.com/w/cpp/language/template_argument_deduction ,我們可以通過以下示例進行模板參數推導template<typen ...
[英]boost asio: Is it thread safe to call tcp::socket::async_read_some() when handler is protected by a strand
我很難完全理解 Boost ASIO 和 strands。 我的印象是,只要處理程序被包裹在一條鏈中,對socket::async_read_some()的調用就是安全的。 這似乎不是這種情況,因為代碼最終會拋出異常。 在我的情況下,第三方庫正在進行Session::readSome()調用。 我在 ...
[英]How can I limit my templatized singleton creation and make the code very generic?
我遇到了一個問題,我想創建一個模板化的 singleton object。如下所示 下一個目標是通過這樣的全局模板化 function 訪問 object 說 有沒有一種方法可以為單個 class 層次結構創建一個 singleton object。對於類似下面的內容,基本類型和派生類型都產生相同 ...
[英]How to define a constexpr constructed array that will have only one instance over many translation units?
我在constexpr class 內生成一個constexpr std::array ,但我只想要 class 的一個實例覆蓋它所使用的所有項目。 我最初將其設為全局變量,但后來我發現如果我在多個翻譯單元中遍歷數組,這些全局變量就會重復。 然后我嘗試使用constexpr function,但我 ...