相关疑难解决方法(0)

什么是C++仿函数及其用途?

我一直在听C++中的仿函数.有人可以给我一个关于它们是什么的概述以及在什么情况下它们会有用吗?

c++ functor function-object function-call-operator

822
推荐指数
8
解决办法
44万
查看次数

C++23 可选的一元绑定和一元返回是什么?

C++23std::optional终于得到了一些非常有用的补充。

由于我对 FP 的了解非常原始,我想知道以下两个操作的语法是什么(根据我的谷歌搜索,这是两个基本的一元操作):

  1. 单子绑定
  2. 单子回归

我最好的猜测是:

单子绑定就是变换

Monadic 返回只是 C++17std::optional 构造函数(8)

c++ monads stdoptional c++23

14
推荐指数
2
解决办法
2536
查看次数

C++ 模板模板参数可以接受采用非类型参数的模板吗?

我有一个这样的函数要fmap为 C++ 实现:

// Given a mapping F from T to U and a container of T, return a container of U
// whose elements are created by the mapping from the original container's
// elements.
template <typename F, template <typename...> typename Container, typename T>
Container<std::invoke_result_t<F&, const T&>> Fmap(F&& f,
                                                   const Container<T>& input);
Run Code Online (Sandbox Code Playgroud)

这个想法是使用模板模板参数 ( Container) 来允许接受任何类似 STL 的容器。我尝试过的实际 STL 中的所有内容都工作正常,但我们的代码库中的自定义容器不起作用,因为它接受非类型模板参数

template <typename Key, int Foo = 256>
class MyContainer;
Run Code Online (Sandbox Code Playgroud)

这会导致 clang 替换失败:

template template argument has …
Run Code Online (Sandbox Code Playgroud)

c++ templates template-templates c++17 c++20

6
推荐指数
1
解决办法
327
查看次数