![](/img/trans.png)
[英]How can I assign element-wise to a tuple using fold expressions?
我有一個有效包裝可變參數std::tuple的類型,如下所示:#include <iostream> #include <tuple> template <typename ...Args> struct Foo { std::tuple<Arg ...
[英]How can I assign element-wise to a tuple using fold expressions?
我有一個有效包裝可變參數std::tuple的類型,如下所示:#include <iostream> #include <tuple> template <typename ...Args> struct Foo { std::tuple<Arg ...
[英]std::function vs callable as template parameter
在下面的示例中,為什么第 20 行會導致第 27 到 30 行描述的錯誤? 在第 33 行調用exec1可以正常工作。 g++ --version回復: ...
[英]Generically wrap member function of object to modify return type
我正在嘗試創建一種能夠接受任何類型的可調用對象並包裝其成員函數之一(在本例中為operator() )以采用相同的參數,但修改(強制轉換)返回類型的類型。 一個例子如下: ReturnConverter可以獲取一個對象並覆蓋該對象的operator()以將它返回的任何內容轉換為Ret 。 問 ...
[英]How can you have multiple lines or statements inside a C++ pack expansion?
假設我有一些像下面這樣的簡單代碼,它只是打印一個元組中的所有值並跟蹤當前迭代。 #include <iostream> #include <tuple> #include <utility> using std::cout; int main() { ...
[英]C++: Using std::apply to iterate through a tuple in 2 parts: up to an index applying a lambda and then after an index applying a different lambda
如果我想使用std::apply遍歷一個元組但不將一個函數應用於整個事物,我該如何分離元組,即將一個函數應用於前n值,另一個應用於它之后的所有值? some_values將是一個元組,它可以具有任何長度和類型,並且length_of_first_part (可能命名得稍微不那么冗長)在編譯時是已 ...
[英]std::visit a std::variant with overloaded free-function instead of function-object
在 C++17 中,是否有一種簡單的方法來 std::visit 帶有重載自由函數的變體,或者我必須使用帶有重載調用運算符的對象? 換句話說,是否可以添加一些簡單的東西來使以下//ERROR! 行編譯在功能上與//OK! 線? ...
[英]std::get does not forward rvalue-reference for std::apply
我想知道為什么std::apply在使用元組中的引用類型時不轉發rvalue-reference (參見Live ): #include <type_traits> #include <tuple> template<typename T> void asser ...
[英]Using std::apply with variadic packs
我正在嘗試創建一個泛型類,它接受一組類型,將它們存儲在元組中,並可以對它們應用函數。 到目前為止我嘗試的是以下內容: 我期望在D上調用base_function時從類B和C調用base_function但是編譯器會生成以下錯誤: 錯誤:沒有匹配的函數用於調用 ' __ ...
[英]Perferct forward a copied std::tuple
我需要一點幫助。 我需要以特定的方式完善元組。 想象一下 被打包的任務將稍后在另一個線程上執行,但是當我調用Apply時,我需要“ callable”來使其元組中的參數擴展並完全像在package_task函數中傳遞時一樣進行轉發。 我無法使用forward_as_tuple因為我 ...
[英]How does std::apply forward parameters without explicit std::forward?
考慮std::apply可能實現: 為什么在調用帶有參數元組的函數( f )來傳遞( t )時,我們不需要在元組std::get<I>(std::forward<Tuple>(t))...每個元素上執行std::forward std::get<I>( ...
[英]std::apply and constant expression?
我在Wandbox中嘗試了以下代碼: 並且編譯器告訴我args...不是常量表達式。 怎么了? ...
[英]Applying a variadic function with std::apply
是否可以使用std :: apply將可變參數函數應用於元組? 例如,以下代碼適用於GCC 6.2.1: 但是,如果我嘗試應用可變參數函數: 編譯器抱怨它不能推斷出vprint模板參數。 好的,讓我們明確地寫出來: 現在,編譯器最終會出現一些模糊的錯誤,這些錯誤暴 ...