小编tow*_*120的帖子

ReactiveUI(RxUI)与Reactive Extensions

来自http://docs.reactiveui.net/en/index.html:

ReactiveUI是一个MVVM框架,允许您使用Reactive Extensions for .NET创建在任何移动或桌面平台上运行的优雅,可测试的用户界面.

RxUI与Reactive Extensions有什么不同?

为什么我更喜欢RxUI而不是MVVMCross/light + Rx?有什么特别的?RxUI可以做一些Rx不能做的事情吗?它更简洁吗?它更舒适吗?

我在github页面https://github.com/reactiveui/ReactiveUI#a-compelling-example上看到了一些例子.但是我不能只用Rx做同样的事情吗?

PS那里有API doc吗?

c# system.reactive reactiveui

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

不能一次多次使用`x`作为可变的

在以下代码(playground)中:

struct Node {
    datum: &'static str,
    edges: Vec<Node>,
}

fn add<'a>(node: &'a mut Node, data: &'static str) -> &'a Node {
    node.edges.push(Node {
        datum: data,
        edges: Vec::new(),
    });
    &node.edges[node.edges.len() - 1] // return just added one
}

fn traverse<F>(root: &Node, callback: &F)
where
    F: Fn(&'static str),
{
    callback(root.datum);
    for node in &root.edges {
        traverse(node, callback);
    }
}

fn main() {
    let mut tree = Node {
        datum: "start",
        edges: Vec::new(),
    };

    let lvl1 = add(&mut tree, "level1"); …
Run Code Online (Sandbox Code Playgroud)

rust

15
推荐指数
2
解决办法
5778
查看次数

C++将私有纯虚方法覆盖为public

为什么会这样?

http://coliru.stacked-crooked.com/a/e1376beff0c157a1

class Base{
private:
    virtual void do_run() = 0;
public:
    void run(){
        do_run();
    }
};

class A : public Base {
public:
    // uplift ??
    virtual void do_run() override {}
};


int main()
{
    A a;
    a.do_run();
}
Run Code Online (Sandbox Code Playgroud)

为什么我可以将PRIVATE虚方法覆盖为公共?

c++ oop overriding virtual-functions private-members

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

C++ 11内联lambda函数没有模板

我想将lambda函数作为回调传递给另一个函数:

void test(const std::function<void()> fn){
    fn();
}
Run Code Online (Sandbox Code Playgroud)

一切正常,一切正常.但.它不会内联它,无论我使用多高的编译器优化级别:
证明

当我玩了一段时间,我发现,使用模板-it变为内联:

template<typename T>     
void test2(T fn){
     fn();
}
Run Code Online (Sandbox Code Playgroud)

proof_2

那么......有没有办法让它在没有模板的情况下内联?为什么它变得内联模板声明?只有函数类型作为模板参数传递,而不是函数本身.

c++ lambda c++11

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

C++ 11 constexpr函数传递参数

请考虑以下代码:

static constexpr int make_const(const int i){
    return i;
}

void t1(const int i)
{
    constexpr int ii = make_const(i);  // error occurs here (i is not a constant expression)
    std::cout<<ii;
}

int main()
{
   t1(12);
}
Run Code Online (Sandbox Code Playgroud)

为什么我在make_const调用时出错?


UPDATE

但是这个有效:

constexpr int t1(const int i)
{
    return make_const(i);
}
Run Code Online (Sandbox Code Playgroud)

但是,这不是:

template<int i>
constexpr bool do_something(){
    return i;
}

constexpr int t1(const int i)
{
    return do_something<make_const(i)>();   // error occurs here (i is not a constant expression)
}
Run Code Online (Sandbox Code Playgroud)

c++ constexpr c++11

11
推荐指数
2
解决办法
1万
查看次数

来自右值的非const类型引用

请考虑以下代码:

class Widget{};

template<typename T>
T &&foo2(T &&t){
    return std::forward<T>( t );
}

/// Return 1st element
template<typename T>
typename std::tuple_element<0, typename std::decay<T>::type >::type  &&foo(T &&t){
    return std::forward< typename std::tuple_element<0, typename std::decay<T>::type >::type >
            ( std::get<0>(t) );
}

Widget w;
auto list = std::make_tuple(
    w,
    Widget()
);


int main()
{
  auto &l  = foo(list );                      // This is NOT work
  //auto &l2 = foo2( std::get<0>(list) );     // This one works.
}
Run Code Online (Sandbox Code Playgroud)

http://coliru.stacked-crooked.com/a/4d3b74ca6f043e45

当我尝试编译时,我收到以下错误:

error: invalid initialization of non-const reference of …
Run Code Online (Sandbox Code Playgroud)

c++ templates rvalue-reference c++11

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

构造函数中的C++通用引用和返回值优化(rvo)

为什么在带有通用引用参数的构造函数的类中不会出现右值优化?

http://coliru.stacked-crooked.com/a/672f10c129fe29a0

#include <iostream>

 template<class ...ArgsIn>
struct C {

  template<class ...Args>
  C(Args&& ... args) {std::cout << "Ctr\n";}        // rvo occurs without &&

  ~C(){std::cout << "Dstr\n";}
};

template<class ...Args> 
auto f(Args ... args) {
    int i = 1;
  return C<>(i, i, i);
}

int main() {
  auto obj = f();
}
Run Code Online (Sandbox Code Playgroud)

输出:

Ctr
Ctr
Dstr
Ctr
Dstr
Dstr
Run Code Online (Sandbox Code Playgroud)

c++ templates rvalue-reference rvo universal-reference

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

在插入时保持std向量/列表排序,或者对所有进行排序

假设我的矢量/列表中有30000个对象.我逐一添加.
我需要他们排序.
是否更快地一次性排序(如std :: sort),或者在逐个添加对象时保持向量/列表的排序?

向量/列表以后不会被修改.

c++ sorting std stdvector

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

C++ 11 std :: forward_as_tuple和std :: forward

std::forward当我将它们用作参数时,我应该使用我的函数参数std::forward_as_tuple吗?

template<class ... List>
void fn(List&& ... list){
   // do I need this forward?
   call_fn( forward_as_tuple( forward<List>(list)... ) );  
}
Run Code Online (Sandbox Code Playgroud)

我知道它们将被存储为右值引用,但还有什么我应该考虑的吗?

c++ templates tuples perfect-forwarding c++11

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

C++静态变量总是在主线程上被破坏吗?

简短的问题:

C++ 11静态(非thread_local)变量是否总是在主线程上被破坏?

它们是否总是仅在程序退出时销毁(考虑到我们不会手动调用它们的析构函数)?

UPDATE

为简洁起见,我们假设调用了析构函数.(我们没有拉插头,我们没有杀掉-9)

c++ static multithreading c++11

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