requires在这里,我详细介绍了概念中使用的子句的一个怪癖的 MWE 。我想要的是一个概念,指示某个函数类型是否可以通过一系列参数调用。我知道这是由 提供的std::invocable,但我在这里所提供的内容将说明这一点。
考虑以下概念:
template <typename func_t, typename... args_t>
concept callable = requires(const func_t& f, const args_t&... args) {f(args...);};
Run Code Online (Sandbox Code Playgroud)
这是相当简单的:如果我有一个func_t,我可以用 来调用它args_t...吗?根据我的理解,只要使用提供的参数调用函数是有效的操作(包括 conversions ) ,这个概念就应该评估为 true 。例如,如果我有一个 lambda:
auto func = [](const double& i) -> void {};
Run Code Online (Sandbox Code Playgroud)
那么以下两个概念的计算结果为true:
callable<decltype(func), int> //true
callable<decltype(func), double> //true
Run Code Online (Sandbox Code Playgroud)
这似乎是因为存在从int到 的转换double。这很好,因为这是我在项目中想要的行为,让我发现了这个问题。
现在,我想使用稍微复杂一点的类型来调用我的 lambda,如下所示:
auto func = [](const type1_t<space1>& t1) -> int {return 1;};
Run Code Online (Sandbox Code Playgroud)
考虑以下类型:
enum space {space1,space2};
template <const space sp> …Run Code Online (Sandbox Code Playgroud) 我正在开发一个大量使用静态多态性的项目。我感兴趣的一个特定用例可以通过静态反射来实现,但我们在 C++ 中仍然没有这种功能。用例看起来像这样:我有一个函数可以从二进制文件读取/写入数据结构:
template <typename data_t> void write_binary(const my_type_t<data_t>& obj)
{
//write a binary file...
}
template <typename data_t> void read_binary(my_type_t<data_t>& obj)
{
//read a binary file...
}
Run Code Online (Sandbox Code Playgroud)
我想强制我只能从相同类型输出的文件中读取数据,例如my_type_t<std::string>只能从 等输出的二进制文件中读取数据my_type_t<std::string>。我想要执行此操作的方法是向二进制文件添加一个小标头确定了 的专业化data_t:
template <typename data_t> void write_binary(const my_type_t<data_t>& obj)
{
//write header type_name(data_t)
//write a binary file...
}
template <typename data_t> void read_binary(my_type_t<data_t>& obj)
{
//read header
//assert header == type_name(data_t)
//read a binary file...
}
Run Code Online (Sandbox Code Playgroud)
我知道它的存在typeid(data_t).name()以及分解它的各种方法,但我想要由标准定义的东西。
所以我的确切问题是:对于任何两种类型type1_t和type2_t,是否存在任何 …
我正在编写一个应用程序,该应用程序有时需要一个网格物体并计算相邻索引。为此,我定义了一个ConcurrentBag对象数组,然后在并行的for循环中,我只检查了一些面孔,如果它们具有邻接关系,则在适当的索引中将索引添加到上述bag中。即:
private bool parallelize = true;
private volatile ConcurrentBag<int>[] edge_adjacencies;
if (parallelize)
{
...
Parallel.For(0, face_count, compute_adjacency_single);
...
}
private void compute_adjacency_single(int cur_idx)
{
edge_adjacencies[cur_idx] = new ConcurrentBag<int>();
foreach(int test_idx in SOME_TEST_SPACE)
{
if (test_idx != cur_idx)
{
bool edge_adj, vertex_adj;
get_adjacency(cur_idx, test_idx, out edge_adj, out vertex_adj);
if (edge_adj && !collection_contains(edge_adjacencies[cur_idx], test_idx))
{
edge_adjacencies[cur_idx].Add(test_idx);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我对集合进行索引,并检查每个集合的大小是否为3(它们都应完全为3):
//DEBUGGING
for (int i = 0; i < face_count; i++)
{
ConcurrentBag<int> cur = edge_adjacencies[i];
if (cur.Count != 3) Console.WriteLine("incorrect:" + …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Redhat 7.7 上安装 tkinter。我已经尝试了“sudo yum install [whatever]”的所有组合,并且每次都会出现“No package [whatever] available”。
pip install tkinter
pip3 install tkinter
sudo yum install python3-tkinter
sudo yum install tkinter
sudo yum install python36-tkinter
sudo yum -y install python36u-tkinter
sudo yum -y install python36-tkinter
sudo yum install tkinter
sudo yum install python36-tkinter
sudo yum install python35-tkinter.x86_64
Run Code Online (Sandbox Code Playgroud)
...ETC
我试图找到我可能需要启用的存储库,但 RedHat 支持都在付费墙后面。我需要启用什么存储库?
此时我实际上正在考虑切换到 Ubuntu,因为 RedHat 给我带来了各种各样的问题。
编辑:我尝试yum search tkinter并得到以下结果:
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
manager
Repo rhel-7-workstation-rpms forced skip_if_unavailable=True due to:
/etc/pki/entitlement/4690243650278863397-key.pem
====================== Matched:tkinter========================== …Run Code Online (Sandbox Code Playgroud)