小编Jak*_*ake的帖子

一种在C++中实现延迟评估的方法

所以我回答了一个关于懒惰评估的问题(这里,我的答案对于那个案例来说太过分了,但这个想法似乎很有趣),这让我想到了如何在C++中进行懒惰的评估.我提出了一个方法,但我不确定这方面的所有陷阱.是否有其他方法可以实现懒惰评估?怎么可能这样做?什么是陷阱,这个和其他设计?

这是我的想法:

#include <iostream>
#include <functional>
#include <memory>
#include <string>

#define LAZY(E) lazy<decltype((E))>{[&](){ return E; }}

template<class T>
class lazy {
private:
    typedef std::function<std::shared_ptr<T>()> thunk_type;
    mutable std::shared_ptr<thunk_type> thunk_ptr;
public:
    lazy(const std::function<T()>& x)
        : thunk_ptr(
            std::make_shared<thunk_type>([x](){
                return std::make_shared<T>(x());
            })) {}
    const T& operator()() const {
        std::shared_ptr<T> val = (*thunk_ptr)();
        *thunk_ptr = [val](){ return val; };
        return *val;
    }
    T& operator()() {
        std::shared_ptr<T> val = (*thunk_ptr)();
        *thunk_ptr = [val](){ return val; };
        return *val;
    }
};

void log(const lazy<std::string>& msg) …
Run Code Online (Sandbox Code Playgroud)

c++ lazy-evaluation c++11

13
推荐指数
2
解决办法
8415
查看次数

Haskell"Functor [::]"中的语法

我在Functor [::] 这里遇到了这个实例,但我不理解语法,并且在代码中的任何地方都没有找到.什么是文件说?

haskell functor

7
推荐指数
1
解决办法
233
查看次数

Mongo shell javascript数组扩展

所以我试图在mongodb shell中使用javascript数组扩展(Array.prototype函数),它们似乎没有被定义.我认为这对我来说没问题,但我非常希望在实际的quires(即group)和map-reduce中使用它们.我使用的是mognodb版本2.4.10.它在这里说2.4 plus应该有ES5阵列扩展.他们只是没有壳?

具体来说,填充方法不起作用

test = [1, 2, 3, 4]
test.fill(0)
Run Code Online (Sandbox Code Playgroud)

没有说TypeError:对象1,2,3没有方法'填充'

javascript arrays shell mongodb

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

标签 统计

arrays ×1

c++ ×1

c++11 ×1

functor ×1

haskell ×1

javascript ×1

lazy-evaluation ×1

mongodb ×1

shell ×1