BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Introducing Reactive Extensions for C++

Introducing Reactive Extensions for C++

This item in japanese

Reactive Extensions for C++, also known as Rx.cpp, is now available for WinRT via C++/CX and OS X via clang. While still in its early stages, a lot of work has been done since the last preview.

Scheduling is a cornerstone of Reactive Extensions. In this release there are five available schedulers including one specifically for Windows’ HWND message loops.

  • Immediate
  • CurrentThread
  • EventLoop
  • NewThread
  • Window

The operators, which are the “async equivalent of STL algorithms” will be familiar to Rx developers: OrderBy, ForEach, Using, Scan, Throttle, TakeUntil, Skip, SkipUntil, ToVector, ToList, Zip, Concat, CombineLatest, Merge, ToAsync, Using, ConnectableObservable, Multicast, Publish, PublishLast, RefCount, ConnectForever, SubscribeOn, ObserveOn.

Special for C++/CX on WinRT are BindCommand, DeferOperation, CoreDispatcherScheduler, FromEventPattern, FromAsyncPattern and ReactiveCommand. The last one comes from Paul Betts’ ReactiveUI.

Here is an example of creating an observable from a range:

//Declare an observable

auto values1 = rxcpp::Range(1, 10);

rxcpp::from(values1)

.for_each(

[](int p) {

cout << p << endl;

});

The source code for Rx.cpp is available on CodePlex under the Apache License 2.0 license.

Rate this Article

Adoption
Style

BT