如何对可变参数模板函数的异构参数包进行通用计算?

2023-11-27

PREMISE:

在尝试了一下可变参数模板之后,我意识到实现任何稍微超出微不足道的元编程任务的东西很快就会变得相当麻烦。特别是,我发现自己希望有一种方式来表现对参数包的通用操作例如iterate, split, loop in a std::for_each- 比如时尚等等。

看完后安德烈·亚历山德雷斯库 (Andrei Alexandrescu) 的演讲来自 C++ and Beyond 2012 的关于以下内容的可取性static if转化为 C++(借用自 C++ 的构造D 编程语言)我有一种感觉static for也会派上用场的——而且我对这些有更多的感觉static构建可以带来好处。

所以我开始想是否有办法实现像这样的东西对于可变参数模板函数的参数包(伪代码):

template<typename... Ts>
void my_function(Ts&&... args)
{
    static for (int i = 0; i < sizeof...(args); i++) // PSEUDO-CODE!
    {
        foo(nth_value_of<i>(args));
    }
}

哪个会被翻译在编译时变成这样的东西:

template<typename... Ts>
void my_function(Ts&&... args)
{
    foo(nth_value_of<0>(args));
    foo(nth_value_of<1>(args));
    // ...
    foo(nth_value_of<sizeof...(args) - 1>(args));
}

原则,static_for将允许更精细的处理:

template<typename... Ts>
void foo(Ts&&... args)
{
    constexpr s = sizeof...(args);

    static for (int i = 0; i < s / 2; i++)
    {
        // Do something
        foo(nth_value_of<i>(args));
    }

    static for (int i = s / 2; i < s; i++)
    {
        // Do something different
        bar(nth_value_of<i>(args));
    }
}

或者使用更具表现力的习语,例如:

template<typename... Ts>
void foo(Ts&&... args)
{
    static for_each (auto&& x : args)
    {
        foo(x);
    }
}

相关工作:

我在网上搜索了一下,发现某物确实存在:

  • 这个链接描述了如何将参数包转换为 Boost.MPL 向量,但这只实现了目标的一半(如果不是更少);
  • 这个问题关于SO似乎需要一个类似且稍微相关的元编程功能(将参数包分成两半) - 实际上,SO上有几个问题似乎与这个问题相关,但我读过的答案都没有解决它恕我直言,令人满意;
  • Boost.Fusion defines algorithms for converting an argument pack into a tuple, but I would prefer:
    1. 不去创造不必要的临时保存可以(并且应该)完美转发给某些通用算法的参数;
    2. have a 小,独立库来做到这一点,而 Boost.Fusion 可能包含比解决这个问题所需的更多的东西。

问题:

是否有一种相对简单的方法(可能通过一些模板元编程)来实现我正在寻找的目标,而不会受到现有方法的限制?


由于我对发现的结果不满意,因此我尝试自己找出解决方案,并最终编写了一个小图书馆它允许对参数包制定通用操作。我的解决方案具有以下特点:

  • 允许迭代所有或some参数包的元素,可能由计算包装上的索引;
  • 允许将参数包的计算部分转发给可变参数函子;
  • 只需要包含一个较短的头文件;
  • 广泛使用完美转发以允许大量内联并避免不必要的复制/移动以最小化性能损失;
  • 迭代算法的内部实现依赖于空基类优化来最小化内存消耗;
  • 扩展和适应很容易(相对而言,考虑到它的模板元编程)。

我先展示一下可以做什么与图书馆,then发布其执行.

用例

下面是一个示例,说明如何for_each_in_arg_pack()函数可用于迭代包的所有参数,并将输入中的每个参数传递给某个客户端提供的函子(当然,如果参数包包含异构类型的值,则函子必须具有通用调用运算符):

// Simple functor with a generic call operator that prints its input. This is used by the
// following functors and by some demonstrative test cases in the main() routine.
struct print
{
    template<typename T>
    void operator () (T&& t)
    {
        cout << t << endl;
    }
};

// This shows how a for_each_*** helper can be used inside a variadic template function
template<typename... Ts>
void print_all(Ts&&... args)
{
    for_each_in_arg_pack(print(), forward<Ts>(args)...);
}

The print上面的函子也可以用于更复杂的计算。特别是,这里是人们如何迭代subset(在这种情况下,一个子范围) 包中的参数:

// Shows how to select portions of an argument pack and 
// invoke a functor for each of the selected elements
template<typename... Ts>
void split_and_print(Ts&&... args)
{
    constexpr size_t packSize = sizeof...(args);
    constexpr size_t halfSize = packSize / 2;

    cout << "Printing first half:" << endl;
    for_each_in_arg_pack_subset(
        print(), // The functor to invoke for each element
        index_range<0, halfSize>(), // The indices to select
        forward<Ts>(args)... // The argument pack
        );

    cout << "Printing second half:" << endl;
    for_each_in_arg_pack_subset(
        print(), // The functor to invoke for each element
        index_range<halfSize, packSize>(), // The indices to select
        forward<Ts>(args)... // The argument pack
        );
}

有时候,一个人可能只是想转发一部分将参数包传递给其他一些可变参数函子,而不是迭代其元素并传递每个元素单独地到一个非变量函子。这就是forward_subpack()算法允许执行以下操作:

// Functor with variadic call operator that shows the usage of for_each_*** 
// to print all the arguments of a heterogeneous pack
struct my_func
{
    template<typename... Ts>
    void operator ()(Ts&&... args)
    {
        print_all(forward<Ts>(args)...);
    }
};

// Shows how to forward only a portion of an argument pack 
// to another variadic functor
template<typename... Ts>
void split_and_print(Ts&&... args)
{
    constexpr size_t packSize = sizeof...(args);
    constexpr size_t halfSize = packSize / 2;

    cout << "Printing first half:" << endl;
    forward_subpack(my_func(), index_range<0, halfSize>(), forward<Ts>(args)...);

    cout << "Printing second half:" << endl;
    forward_subpack(my_func(), index_range<halfSize, packSize>(), forward<Ts>(args)...);
}

对于更具体的任务,当然可以通过以下方式检索包中的特定参数indexing他们。这就是nth_value_of()函数允许与其助手一起执行操作first_value_of() and last_value_of():

// Shows that arguments in a pack can be indexed
template<unsigned I, typename... Ts>
void print_first_last_and_indexed(Ts&&... args)
{
    cout << "First argument: " << first_value_of(forward<Ts>(args)...) << endl;
    cout << "Last argument: " << last_value_of(forward<Ts>(args)...) << endl;
    cout << "Argument #" << I << ": " << nth_value_of<I>(forward<Ts>(args)...) << endl;
}

如果参数包是同质另一方面(即所有参数都具有相同的类型),如下所示的表述可能更可取。这is_homogeneous_pack<>元函数允许确定参数包中的所有类型是否同质,主要用于static_assert()声明:

// Shows the use of range-based for loops to iterate over a
// homogeneous argument pack
template<typename... Ts>
void print_all(Ts&&... args)
{
    static_assert(
        is_homogeneous_pack<Ts...>::value, 
        "Template parameter pack not homogeneous!"
        );

    for (auto&& x : { args... })
    {
        // Do something with x...
    }

    cout << endl;
}

最后,自从lambdas只是句法糖对于函子,它们也可以与上述算法结合使用;然而,直到泛型 lambda将由 C++ 支持,这仅适用于同质参数包。下面的例子也展示了使用homogeneous-type<>元函数,返回同构包中所有参数的类型:

 // ...
 static_assert(
     is_homogeneous_pack<Ts...>::value, 
     "Template parameter pack not homogeneous!"
     );
 using type = homogeneous_type<Ts...>::type;
 for_each_in_arg_pack([] (type const& x) { cout << x << endl; }, forward<Ts>(args)...);

这基本上是图书馆允许做的事情,但我相信甚至可以延长来执行更复杂的任务。

执行

现在是实现,它本身有点棘手,所以我将依靠注释来解释代码并避免使这篇文章太长(也许已经是):

#include <type_traits>
#include <utility>

//===============================================================================
// META-FUNCTIONS FOR EXTRACTING THE n-th TYPE OF A PARAMETER PACK

// Declare primary template
template<int I, typename... Ts>
struct nth_type_of
{
};

// Base step
template<typename T, typename... Ts>
struct nth_type_of<0, T, Ts...>
{
    using type = T;
};

// Induction step
template<int I, typename T, typename... Ts>
struct nth_type_of<I, T, Ts...>
{
    using type = typename nth_type_of<I - 1, Ts...>::type;
};

// Helper meta-function for retrieving the first type in a parameter pack
template<typename... Ts>
struct first_type_of
{
    using type = typename nth_type_of<0, Ts...>::type;
};

// Helper meta-function for retrieving the last type in a parameter pack
template<typename... Ts>
struct last_type_of
{
    using type = typename nth_type_of<sizeof...(Ts) - 1, Ts...>::type;
};

//===============================================================================
// FUNCTIONS FOR EXTRACTING THE n-th VALUE OF AN ARGUMENT PACK

// Base step
template<int I, typename T, typename... Ts>
auto nth_value_of(T&& t, Ts&&... args) ->
    typename std::enable_if<(I == 0), decltype(std::forward<T>(t))>::type
{
    return std::forward<T>(t);
}

// Induction step
template<int I, typename T, typename... Ts>
auto nth_value_of(T&& t, Ts&&... args) ->
    typename std::enable_if<(I > 0), decltype(
        std::forward<typename nth_type_of<I, T, Ts...>::type>(
            std::declval<typename nth_type_of<I, T, Ts...>::type>()
            )
        )>::type
{
    using return_type = typename nth_type_of<I, T, Ts...>::type;
    return std::forward<return_type>(nth_value_of<I - 1>((std::forward<Ts>(args))...));
}

// Helper function for retrieving the first value of an argument pack
template<typename... Ts>
auto first_value_of(Ts&&... args) ->
    decltype(
        std::forward<typename first_type_of<Ts...>::type>(
            std::declval<typename first_type_of<Ts...>::type>()
            )
        )
{
    using return_type = typename first_type_of<Ts...>::type;
    return std::forward<return_type>(nth_value_of<0>((std::forward<Ts>(args))...));
}

// Helper function for retrieving the last value of an argument pack
template<typename... Ts>
auto last_value_of(Ts&&... args) ->
    decltype(
        std::forward<typename last_type_of<Ts...>::type>(
            std::declval<typename last_type_of<Ts...>::type>()
            )
        )
{
    using return_type = typename last_type_of<Ts...>::type;
    return std::forward<return_type>(nth_value_of<sizeof...(Ts) - 1>((std::forward<Ts>(args))...));
}

//===============================================================================
// METAFUNCTION FOR COMPUTING THE UNDERLYING TYPE OF HOMOGENEOUS PARAMETER PACKS

// Used as the underlying type of non-homogeneous parameter packs
struct null_type
{
};

// Declare primary template
template<typename... Ts>
struct homogeneous_type;

// Base step
template<typename T>
struct homogeneous_type<T>
{
    using type = T;
    static const bool isHomogeneous = true;
};

// Induction step
template<typename T, typename... Ts>
struct homogeneous_type<T, Ts...>
{
    // The underlying type of the tail of the parameter pack
    using type_of_remaining_parameters = typename homogeneous_type<Ts...>::type;

    // True if each parameter in the pack has the same type
    static const bool isHomogeneous = std::is_same<T, type_of_remaining_parameters>::value;

    // If isHomogeneous is "false", the underlying type is the fictitious null_type
    using type = typename std::conditional<isHomogeneous, T, null_type>::type;
};

// Meta-function to determine if a parameter pack is homogeneous
template<typename... Ts>
struct is_homogeneous_pack
{
    static const bool value = homogeneous_type<Ts...>::isHomogeneous;
};

//===============================================================================
// META-FUNCTIONS FOR CREATING INDEX LISTS

// The structure that encapsulates index lists
template <unsigned... Is>
struct index_list
{
};

// Collects internal details for generating index ranges [MIN, MAX)
namespace detail
{
    // Declare primary template for index range builder
    template <unsigned MIN, unsigned N, unsigned... Is>
    struct range_builder;

    // Base step
    template <unsigned MIN, unsigned... Is>
    struct range_builder<MIN, MIN, Is...>
    {
        typedef index_list<Is...> type;
    };

    // Induction step
    template <unsigned MIN, unsigned N, unsigned... Is>
    struct range_builder : public range_builder<MIN, N - 1, N - 1, Is...>
    {
    };
}

// Meta-function that returns a [MIN, MAX) index range
template<unsigned MIN, unsigned MAX>
using index_range = typename detail::range_builder<MIN, MAX>::type;

//===============================================================================
// CLASSES AND FUNCTIONS FOR REALIZING LOOPS ON ARGUMENT PACKS

// Implementation inspired by @jogojapan's answer to this question:
// http://stackoverflow.com/questions/14089637/return-several-arguments-for-another-function-by-a-single-function

// Collects internal details for implementing functor invocation
namespace detail
{
    // Functor invocation is realized through variadic inheritance.
    // The constructor of each base class invokes an input functor.
    // An functor invoker for an argument pack has one base class
    // for each argument in the pack

    // Realizes the invocation of the functor for one parameter
    template<unsigned I, typename T>
    struct invoker_base
    {
        template<typename F, typename U>
        invoker_base(F&& f, U&& u) { f(u); }
    };

    // Necessary because a class cannot inherit the same class twice
    template<unsigned I, typename T>
    struct indexed_type
    {
        static const unsigned int index = I;
        using type = T;
    };

    // The functor invoker: inherits from a list of base classes.
    // The constructor of each of these classes invokes the input
    // functor with one of the arguments in the pack.
    template<typename... Ts>
    struct invoker : public invoker_base<Ts::index, typename Ts::type>...
    {
        template<typename F, typename... Us>
        invoker(F&& f, Us&&... args)
            :
            invoker_base<Ts::index, typename Ts::type>(std::forward<F>(f), std::forward<Us>(args))...
        {
        }
    };
}

// The functor provided in the first argument is invoked for each
// argument in the pack whose index is contained in the index list
// specified in the second argument
template<typename F, unsigned... Is, typename... Ts>
void for_each_in_arg_pack_subset(F&& f, index_list<Is...> const& i, Ts&&... args)
{
    // Constructors of invoker's sub-objects will invoke the functor.
    // Note that argument types must be paired with numbers because the
    // implementation is based on inheritance, and one class cannot
    // inherit the same base class twice.
    detail::invoker<detail::indexed_type<Is, typename nth_type_of<Is, Ts...>::type>...> invoker(
        f,
        (nth_value_of<Is>(std::forward<Ts>(args)...))...
        );
}

// The functor provided in the first argument is invoked for each
// argument in the pack
template<typename F, typename... Ts>
void for_each_in_arg_pack(F&& f, Ts&&... args)
{
    for_each_in_arg_pack_subset(f, index_range<0, sizeof...(Ts)>(), std::forward<Ts>(args)...);
}

// The functor provided in the first argument is given in input the
// arguments in whose index is contained in the index list specified
// as the second argument.
template<typename F, unsigned... Is, typename... Ts>
void forward_subpack(F&& f, index_list<Is...> const& i, Ts&&... args)
{
    f((nth_value_of<Is>(std::forward<Ts>(args)...))...);
}

// The functor provided in the first argument is given in input all the
// arguments in the pack.
template<typename F, typename... Ts>
void forward_pack(F&& f, Ts&&... args)
{
    f(std::forward<Ts>(args)...);
}

结论

当然,即使我对这个问题提供了自己的答案(实际上因为这个事实),我很好奇是否存在我错过的替代或更好的解决方案 - 除了问题的“相关作品”部分中提到的解决方案之外。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何对可变参数模板函数的异构参数包进行通用计算? 的相关文章

  • 如何在 Visual Studio 2010 中增强 XAML 设计器?

    当我使用 XAML 设计器时 进入设计器和退出设计器是如此困难和缓慢 当我这样做时 Visual Studio 卡了一段时间 有什么方法可以增强 XAML 设计器和编辑器吗 Ant 保存 XAML 文件时非常慢 这通常意味着您可能有复杂的
  • 在 C# 中创建具有单独列的分隔文本

    我一直在尝试在 C 中创建一个制表符限制的文本文件 以便数据正确显示在单独的列中 Firstname Lastname Age John Smith 17 James Sawyer 31 我尝试过 t 字符 但我得到的只是 Firstnam
  • 使用 Unity 在构造函数中使用属性依赖注入

    好的 我在基类中定义了一个依赖属性 我尝试在其派生类的构造函数内部使用它 但这不起作用 该属性显示为 null Unity 在使用 container Resolve 解析实例后解析依赖属性 我的另一种选择是将 IUnityContaine
  • 单元测试一起运行时失败,单独运行时通过

    所以我的单元测试遇到了一些问题 我不能只是将它们复制并粘贴到这里 但我会尽力而为 问题似乎是 如果我一项一项地运行测试 一切都会按预期进行 但如果我告诉它一起运行测试 则 1 5 将通过 TestMethod public void Obj
  • 读取文件特定行号的有效方法。 (奖励:Python 手册印刷错误)

    我有一个 100 GB 的文本文件 它是来自数据库的 BCP 转储 当我尝试导入它时BULK INSERT 我在第 219506324 行上收到一个神秘错误 在解决此问题之前 我想看看这一行 但可惜的是我最喜欢的方法 import line
  • 如何访问另一个窗体上的ListView控件

    当单击与 ListView 所在表单不同的表单中的按钮时 我试图填充 ListView 我在 Form1 中创建了一个方法以在 Form2 中使用 并将参数传递给 Form1 中的方法 然后填充 ListView 当我调试时 我得到了传递的
  • 如何在 C# 中定义文本框数组?

    您好 当我在 Windows 申请表上创建文本框时 我无法将其命名为 box 0 box 1 等 我这样做的目的是因为我想循环使用它们 其实我发现TextBox array firstTextBox secondTextBox 也有效
  • 在一个字节中存储 4 个不同的值

    我有一个任务要做 但我不知道从哪里开始 我不期待也绝对不想要代码中的答案 我想要一些关于该怎么做的指导 因为我感到有点失落 将变量打包和解包到一个字节中 您需要在一个字节中存储 4 个不同的值 这些值为 NAME RANGE BITS en
  • 如何将整数转换为 void 指针?

    在 C 中使用线程时 我面临警告 警告 从不同大小的整数转换为指针 代码如下 include
  • Visual Studio 中的测试单独成功,但一组失败

    当我在 Visual Studio 中单独运行测试时 它们都顺利通过 然而 当我同时运行所有这些时 有些通过 有些失败 我尝试在每个测试方法之间暂停 1 秒 但没有成功 有任何想法吗 在此先感谢您的帮助 你们可能有一些共享数据 检查正在使用
  • 如何将自定义 JSON 文件添加到 IConfiguration 中?

    我正在使用 asp net Autofac 我正在尝试加载自定义 JSON 配置文件 并基于该文件创建 实例化 IConfiguration 实例 或者至少将我的文件包含到默认情况下构建的 IConfiguration asp net 中
  • 使用 Moq 使用内部构造函数模拟类型

    我正在尝试模拟 Microsoft Sync Framework 中的一个类 它只有一个内部构造函数 当我尝试以下操作时 var fullEnumerationContextMock new Mock
  • 如何使用 Mongodb C# 驱动程序连接多个集合

    我需要将 3 个集合与多个集合合并在一起 lookup我在 C 驱动程序中尝试过 它允许我 lookup用户采集但无法执行秒 lookup用于设置集合 有人可以帮忙吗 db Transactions aggregate lookup fro
  • 私有模板函数

    我有一堂课 C h class C private template
  • HttpWebRequest 在第二次调用时超时

    为什么以下代码在第二次 及后续 运行时超时 代码挂在 using Stream objStream request GetResponse GetResponseStream 然后引发 WebException 表示请求已超时 我已经尝试过
  • 用于 C# 的 TripleDES IV?

    所以当我说这样的话 TripleDES tripledes TripleDES Create Rfc2898DeriveBytes pdb new Rfc2898DeriveBytes password plain tripledes Ke
  • memset 未填充数组

    u32 iterations 5 u32 ecx u32 malloc sizeof u32 iterations memset ecx 0xBAADF00D sizeof u32 iterations printf 8X n ecx 0
  • Linq-to-entities,在一个查询中获取结果+行数

    我已经看到了有关此事的多个问题 但它们已经有 2 年 或更长 的历史了 所以我想知道这方面是否有任何变化 基本思想是填充网格视图并创建自定义分页 所以 我还需要结果和行数 在 SQL 中 这将类似于 SELECT COUNT id Id N
  • 检查Windows控制台中是否按下了键[重复]

    这个问题在这里已经有答案了 可能的重复 C 控制台键盘事件 https stackoverflow com questions 2067893 c console keyboard events 我希望 Windows 控制台程序在按下某个
  • 在客户端系统中安装后桌面应用程序无法打开

    我目前正在使用 Visual Studio 2017 和 4 6 1 net 框架 我为桌面应用程序创建了安装文件 安装程序在我的系统中完美安装并运行 问题是安装程序在其他计算机上成功安装 但应用程序无法打开 edit 在客户端系统中下载了

随机推荐

  • 如何将compile_commands.json与clang python绑定一起使用?

    我有以下脚本尝试打印给定 C 文件中的所有 AST 节点 当在具有简单包含的简单文件 同一目录中的头文件等 上使用它时 效果很好 usr bin env python from argparse import ArgumentParser
  • 如何在生产中禁用转储 symfony 功能

    如何禁用dump 功能 什么时候在生产环境中 如果我忘记了转储功能 它会崩溃并出现 500 错误 你应该删除dump 来自您的生产代码 它不必在那里 But as noted by Cerad 因为当您在签入之前忘记删除它们时可能会很烦人
  • 我如何告诉 PyCharm 参数的预期类型是什么?

    当涉及到构造函数 赋值和方法调用时 PyCharm IDE 非常擅长分析我的源代码并找出每个变量应该是什么类型 我喜欢它正确的时候 因为它为我提供了良好的代码完成和参数信息 并且如果我尝试访问不存在的属性 它会给我警告 但当涉及到参数时 它
  • 映射缩减组合器

    我有一个带有映射器 减速器和组合器的简单映射缩减代码 映射器的输出被传递到组合器 但是对于reducer来说 传递的不是combiner的输出 而是mapper的输出 请帮忙 Code package Combiner import jav
  • 如何在 React Native 中限制 google 登录到我公司的电子邮件域 (@company.com)?

    Question 阻止用户使用不以 mycompany com 结尾的电子邮件地址通过 Firebase Google 身份验证登录我们的内部应用程序的最佳方法是什么 Goal 防止用户使用错误的电子邮件登录应用程序 获取用户的公司电子邮件
  • Python pip install 以“命令错误,退出状态 1:...”结束

    我是 python 新手 我正在尝试运行一些需要一些库的基本代码 当我尝试安装库 例如 pip install matplotlib venn 时 我收到这个长错误 ERROR Command errored out with exit s
  • 如何使用 JavaScript 以编程方式打开文件选择器? [复制]

    这个问题在这里已经有答案了 可能的重复 在 JavaScript 中 我可以通过编程方式为文件输入元素触发 click 事件吗 我天真地尝试了以下方法 使用 JavaScript 以编程方式打开文件选择器 请参阅 fiddlehere
  • 每当 firebase 发生任何更改时,自动向所有用户发送通知 [关闭]

    Closed 这个问题需要多问focused 目前不接受答案 当 Firebase 发生更改时 如何通知所有用户 我不想手动执行此操作 您应该使用由实时数据库触发器触发的 Firebase Cloud Function 请参阅文档here
  • 如何启动Manifest中提到的不存在的Activity?

    我正在尝试开发一个 动态 Android 应用程序 动态是指我在清单中列出了一个在运行时 构建 的活动 我可以很好地构建所需的活动 但是 当我尝试启动它时 我的应用程序失败了 java lang RuntimeException Unabl
  • std::sort 会改变相等元素的相对顺序吗?

    标准是否通过使用 std sort 保证相等元素的顺序不会改变 呃 忘记了这个术语 或者我是否需要考虑替代解决方案来实现此目标 std sort不保证稳定 您试图想到的术语 正如你猜想的那样 std stable sort保证稳定 std
  • 如何更改AlertDialog中的文本颜色

    如何更改 AlertDialog 中的文本颜色
  • 如何使中心裁剪图像响应?

    基于一个现有答案 我已经设法居中裁剪图像 不过 我在使中心裁剪图像具有响应能力时遇到了困难 Question 当我减小网络浏览器窗口的大小时 中心裁剪图像不能很好地缩小 相反 它保持固定状态height and width and spil
  • 多重继承的虚方法表

    我正在读这篇文章 虚拟方法表 上面文章中的例子 class B1 public void f0 virtual void f1 int int in b1 class B2 public virtual void f2 int int in
  • 在组件状态下从数组中删除元素

    我正在尝试找到在组件状态下从数组中删除元素的最佳方法 因为我不应该修改this state直接变量 是否有比我这里更好的方法 更简洁 从数组中删除元素 onRemovePerson function index this setState
  • 断言失败:预测必须 >= 0,条件 x >= y 不按元素成立

    我正在运行一个多类模型 总共 40 个类 2000 个时期 该模型在 828 纪元之前运行良好 但在 829 纪元时它给了我一个 InvalidArgumentError 参见下面的屏幕截图 下面是我用来构建模型的代码 n cats 40
  • 获取 IndexedDB 中添加记录的键

    我在 IndexedDB 中有这段代码 var request objectStore add entryType entryType entryDate t 现在我想知道刚刚添加的这条记录的密钥 我该怎么做 I found 本文 和这个
  • iOS 版 GoogleMaps SDK 上是否存在标记动画?

    是否可以移动 旋转GMSMarker on GMSMapView有动画 1 2 中的补充是GMSMarker类有一个animated属性 我想你刚刚将其设置为YES 在通过设置其标记将标记添加到地图之前map属性 虽然我还没有尝试过 htt
  • 如何将原子计数器添加到 powershell ForEach -Parallel 循环

    在这个问题中 解释了如何添加到并发ThreadSafe集合Powershell 如何将结果添加到数组 ForEach Object Parallel 我有一个更简单的用例 我只想增加一个值 整数 是否可以在 Powershell 中使用某种
  • PerformSelector:withObject: 及其保留行为

    这是SO中已经回答的问题但是我在 Apple 文档中找不到它 你能指出我正确的方向吗 在以下主题中 在将对象传递给 performSelector withObject afterDelay 之前是否必须保留该对象 对 PerformSel
  • 如何对可变参数模板函数的异构参数包进行通用计算?

    PREMISE 在尝试了一下可变参数模板之后 我意识到实现任何稍微超出微不足道的元编程任务的东西很快就会变得相当麻烦 特别是 我发现自己希望有一种方式来表现对参数包的通用操作例如iterate split loop in a std for