GithubHelp home page GithubHelp logo

snakster / cpp.react Goto Github PK

View Code? Open in Web Editor NEW
1.0K 76.0 128.0 2.1 MB

C++React: A reactive programming library for C++11.

Home Page: http://snakster.github.io/cpp.react/

License: Boost Software License 1.0

CMake 0.58% C++ 99.42%

cpp.react's Introduction

C++React

C++React is reactive programming library for C++14. It enables the declarative definition of data dependencies between state and event flows. Based on these definitions, propagation of changes is handled automatically.

Here's a simple example:

using namespace react;

void AddNumbers(int a, int b)  { return a + b; }

// Two state variable objects. You can change their values manually.
auto a = StateVar<int>::Create(0);
auto b = StateVar<int>::Create(0);

// Another state object. Its value is calculated automatically based on the given function and arguments.
// If the arguments change, the value is re-calculated.
auto sum = State<int>::Create(AddNumbers, a, b);

// sum == 0
a.Set(21);
// sum == 21
b.Set(21);
// sum == 42

The underlying system constructs a dependency graph to collect which values are affected by a change, and in which order they have to be re-calculated. This guarantees several properties:

  • correctness - no updates are forgotten;
  • consistency - no value is updated before all its incoming dependencies have been updated;
  • efficiency - no value is re-calculated more than once per update cycle, and changes are only propagated along paths where a new value is different from the old one.

The system also knows when it's safe to update values in parallel from multiple threads, and it can do live profiling to decide when that's worthwhile.

Development status

I'm currently in the process of rewriting the library more or less from scratch and many things are still broken or outdated.

The old, but stable and documented version is still available in this branch.

cpp.react's People

Contributors

schlangster avatar snakster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp.react's Issues

Is this project dead

This project looks just to what I need for a project, but last update is from 2017, the readme states:

I'm currently in the process of rewriting the library more or less from scratch and many things are still broken or outdated.

Apparetly this is not maintaned anymore. :(

Question: how to use with multiple files and not get linker errors

I'm trying to write classes that have VarSignal members. My problem is with the REACTIVE_DOMAIN macro.

When I include these classes I get linker errors because there is now a duplicate symbol _D_initializer_ in each .o file.

The examples all show one page of code in a single .cpp file (and no header files)

//  DataSource.hpp
#ifndef DataSource_hpp
#define DataSource_hpp

#include "react/Domain.h"
#include "react/Signal.h"
#include "react/Event.h"

REACTIVE_DOMAIN(D, react::sequential)

class DataSource {
 public:
    react::VarSignal<D, int> numDimensions = react::MakeVar<D>(0);
    react::EventSource<D>  didLoad         = react::MakeEventSource<D>();
};

#endif /* DataSource_hpp */
// ofApp.cpp
#pragma once

#import "DataSource.hpp"

class ofApp {
 public:
  // ...

 private:
  DataSource dataSource;
};

The linker now fails because D has been defined twice.

duplicate symbol _D_initializer_ in:
    /Users/crucial/Library/Developer/Xcode/DerivedData/PlaySPLOM-gwpsbmgveykcqsheakzuilcqldtb/Build/Intermediates/PlaySPLOM.build/Debug/PlaySPLOM.build/Objects-normal/x86_64/DataSource.o
    /Users/crucial/Library/Developer/Xcode/DerivedData/PlaySPLOM-gwpsbmgveykcqsheakzuilcqldtb/Build/Intermediates/PlaySPLOM.build/Debug/PlaySPLOM.build/Objects-normal/x86_64/ofApp.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Furthermore, should all classes in this application use the same D ? Or should each create their own ? (with a unique name?)
Where ideally should the domain be declared ? I tried

I realize the library is experimental, but I quite like the syntax and was hoping to get this to work for an openFrameworks data visualization/sonification project.

thanks

Misleading example in BasicSignals.cpp / Example 4

        SignalT<float> Average = Iterate(
            Input,
            0.0f,
            [] (int sample, float oldAvg) {
                return (oldAvg + sample) / 2.0f;
            });

This does not calculate an average. This code calculates

Therefore, the code

Sensor mySensor;
mySensor.Input << 10 << 5 << 10 << 8;
cout << "Average: " << mySensor.Average() << endl;

Produces the output

Example 4 - Creating stateful signals (2)
Average: 7.75

The average of the values (10, 5, 10, 8) is 8.25, not 7.75.

Code isn't 64-bit clean in Microsoft compilers

For example, on Visual Studio 2013 Update 2, we see the following (correct) warnings from cl.exe after adding a 64-bit configuration:

PulsecountEngine.cpp
....\src\engine\PulsecountEngine.cpp(233): warning C4267: 'initializing' : conversion from 'size_t' to 'const react::impl::uint', possible loss of data
SubtreeEngine.cpp
....\src\engine\SubtreeEngine.cpp(181): warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data

This is because ints are 4 bytes on cl.exe 64 -bit code, but size_t is 8 bytes.

Issues when building as a dynamic library

When building CppReact into a dynamic library, the REACTIVE_DOMAIN() macro creates separate instances of the Engine and the InputManager for both the library and the library consumer.

This is because Instance() is defined in a header and declares static variables. However, given the nature of dynamic libraries, this actually creates 2 versions, 1 in the dynamic library's static address space and another in the static address space of application using the dynamic library. You can imagine how this might cause issues for someone using CppReact in a dynamic library.

For a discussion, see: http://stackoverflow.com/questions/8623657/multiple-instances-of-singleton-across-shared-libraries-on-linux

(For reference, I'm on mac building with clang)

OS/domain-specific Examples

I'd like to see a few simple examples of different OS's handling mouse-clicks and the like using C++React. I like the look of the library, but it's not clear from the documentation exactly how to use it to handle UI events on specific platforms.

possible bug in EngineInterface

///////////////////////////////////////////////////////////////////////////////////////////////////
/// EngineInterface - Static wrapper for IReactiveEngine
///////////////////////////////////////////////////////////////////////////////////////////////////
template
<
    typename D,
    typename TEngine
>
struct EngineInterface
{
    static void OnTurnAdmissionStart(TurnT& turn)
    {
        Instance().OnTurnAdmissionEnd(turn); // <-- is this a bug? should it call *Start* not *End*?
    }

src\logging\eventlog.cpp(20): error C2664:

When building with VS 2015, it shows error:

src\logging\eventlog.cpp(20): error C2664: 'std::chrono::time_point<std::chrono::steady_clock,std::chrono::steady_clock::duration>::time_point(std::chrono::time_point<std::chrono::steady_clock,std::chrono::steady_clock::duration> &&)': cannot convert argument 1 from 'std::chrono::system_clock::time_point' to 'const std::chrono::steady_clock::duration &'
1>  d:\apps\cpp.react-master\src\logging\eventlog.cpp(20): note: Reason: cannot convert from 'std::chrono::system_clock::time_point' to 'const std::chrono::steady_clock::duration'
1>  d:\apps\cpp.react-master\src\logging\eventlog.cpp(20): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Support of higher order FRP?

Could you elaborate which design goals you have when rewriting your library?
Are you only planning to support static computation graphs or are you considering higher order of FRP?

For instance, are you considering implementing operators over Observer<Observer<T>> ?
There are many use cases but supporting those are not for free.

EDIT:
Just noticed that the last commit was a year ago. Any (design) specific roadblocks ?

MakeSignal compilation error with Visual Studio 2017 using compiler flag /std:c++17 or /std:c++latest

cpp.react fails to compile on Visual Studio 2017 15.5.7 when attempting to use the C++17 compiler. Specifically, any code that attempts to call MakeSignal() gives build errors.

For example, building a single file BasicAlgorithms.cpp (using ctrl-F7) gives this error when compiler flag /std::c++17 is enabled in the project properties (under C/C++ --> Language --> C++ Language Standard):

1>------ Build started: Project: Example_BasicAlgorithms, Configuration: Debug x64 ------
1>BasicAlgorithms.cpp
1>c:\git\rtvis\3rdparty\intel_tbb\include\tbb\task_group.h(113): error C4996: 'std::uncaught_exception': warning STL4006: std::uncaught_exception() is deprecated in C++17. It is superseded by std::uncaught_exceptions(), plural. You can define _SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.12.25827\include\exception(17): note: see declaration of 'std::uncaught_exception'
1>c:\git\cpp.react\include\react\detail\graph\algorithmnodes.h(371): error C2668: 'react::impl::apply': ambiguous call to overloaded function
1>c:\git\cpp.react\include\react\common\util.h(47): note: could be 'void react::impl::apply<react::impl::SyncedIterateByRefNode<D,S,E,react::impl::AddIterateByRefRangeWrapper<E,S,F,int>,int>::Tick::<lambda_fda7c352706d1102d1708ac0ea940db4>,std::tuple<std::shared_ptr>&>(F &&,T)'
1> with
1> [
1> D=example6::D,
1> S=std::vector<int,std::allocator>,
1> E=int,
1> TNode=react::impl::SignalNodeexample6::D,int,
1> F=react::impl::SyncedIterateByRefNode<example6::D,std::vector<int,std::allocator>,int,react::impl::AddIterateByRefRangeWrapper<int,std::vector<int,std::allocator>,F,int>,int>::Tick::<lambda_fda7c352706d1102d1708ac0ea940db4>,
1> T=std::tuple<std::shared_ptr<react::impl::SignalNodeexample6::D,int>> &
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.12.25827\include\tuple(1043): note: or 'decltype(auto) std::apply<react::impl::SyncedIterateByRefNode<D,S,E,react::impl::AddIterateByRefRangeWrapper<E,S,F,int>,int>::Tick::<lambda_fda7c352706d1102d1708ac0ea940db4>,std::tuple<std::shared_ptr>&>(_Callable &&,_Tuple)' [found using argument-dependent lookup]
1> with
1> [
1> D=example6::D,
1> S=std::vector<int,std::allocator>,
1> E=int,
1> TNode=react::impl::SignalNodeexample6::D,int,
1> _Callable=react::impl::SyncedIterateByRefNode<example6::D,std::vector<int,std::allocator>,int,react::impl::AddIterateByRefRangeWrapper<int,std::vector<int,std::allocator>,F,int>,int>::Tick::<lambda_fda7c352706d1102d1708ac0ea940db4>,
1> _Tuple=std::tuple<std::shared_ptr<react::impl::SignalNodeexample6::D,int>> &
1> ]
1>c:\git\cpp.react\include\react\detail\graph\algorithmnodes.h(355): note: while trying to match the argument list '(react::impl::SyncedIterateByRefNode<D,S,E,react::impl::AddIterateByRefRangeWrapper<E,S,F,int>,int>::Tick::<lambda_fda7c352706d1102d1708ac0ea940db4>, std::tuple<std::shared_ptr>)'
1> with
1> [
1> D=example6::D,
1> S=std::vector<int,std::allocator>,
1> E=int
1> ]
1> and
1> [
1> TNode=react::impl::SignalNodeexample6::D,int
1> ]
1>c:\git\cpp.react\include\react\detail\graph\algorithmnodes.h(355): note: while compiling class template member function 'void react::impl::SyncedIterateByRefNode<D,S,E,react::impl::AddIterateByRefRangeWrapper<E,S,F,int>,int>::Tick(void *)'
1> with
1> [
1> D=example6::D,
1> S=std::vector<int,std::allocator>,
1> E=int
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.12.25827\include\type_traits(517): note: see reference to class template instantiation 'react::impl::SyncedIterateByRefNode<D,S,E,react::impl::AddIterateByRefRangeWrapper<E,S,F,int>,int>' being compiled
1> with
1> [
1> D=example6::D,
1> S=std::vector<int,std::allocator>,
1> E=int
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.12.25827\include\memory(1284): note: see reference to class template instantiation 'std::is_convertible<_Yty *,_Ty *>' being compiled
1> with
1> [
1> _Yty=NodeT,
1> _Ty=react::impl::SignalNode<example6::D,std::vector<int,std::allocator>>
1> ]
1>c:\git\cpp.react\include\react\algorithm.h(145): note: see reference to class template instantiation 'std::_SP_pointer_compatible<NodeT,TNode>' being compiled
1> with
1> [
1> TNode=react::impl::SignalNode<example6::D,std::vector<int,std::allocator>>
1> ]
1>c:\git\cpp.react\examples\src\basicalgorithms.cpp(285): note: see reference to function template instantiation 'react::Signal<example6::D,std::vector<E,std::allocator<_Ty>>> react::Iterate<D,E,std::vector<_Ty,std::allocator<_Ty>>,example6::Sensor::<lambda_5beba5edb4fefc40f76e4dbbca2548f7>,S,std::vector<_Ty,std::allocator<_Ty>>>(const react::Events<D,E> &,V &&,const react::SignalPack<D,S> &,FIn &&)' being compiled
1> with
1> [
1> E=int,
1> _Ty=int,
1> D=example6::D,
1> S=int,
1> V=std::vector<int,std::allocator>,
1> FIn=example6::Sensor::<lambda_5beba5edb4fefc40f76e4dbbca2548f7>
1> ]
1>Done building project "Example_BasicAlgorithms.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Note: this exact same file compiles cleanly when the compiler flag /std:c++14 is used instead:

1>------ Build started: Project: Example_BasicAlgorithms, Configuration: Debug x64 ------
1>BasicAlgorithms.cpp
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Do you know how to avoid this "ambiguous call to overloaded function" compiler error in C++17 mode?
Any pointers would be greatly appreciated.
Thanks!

List of dependencies?

It seems TBB is a hard dependency? It would be nice to know that on the front-page and/or README.

Or perhaps I have missed something -- I wanted to use this project on an embedded micro-controller, but I don't think TBB would run there? Just looking to clarify whether it is even possible to use cpp.react without TBB (sequential only?), or if TBB should work on non-Intel platforms?

No lifting for method operators

struct V {
  int x, y;
  V(int _x,int _y):x(_x),y(_y) { }
  V() {}
  inline const V operator+(const V& v1) const {
    return V(v1.x+x, v1.y+y);
  }
};
bool operator==(const V& lhs, const V& rhs){
  return lhs.x == rhs.x && lhs.y == rhs.y;
}

VarSignalT<V> b1 = MakeVar<GG, V>(V(1,1));
VarSignalT<V> b2 = MakeVar<GG, V>(V(1,1));
SignalT<V> b = b1 + b2;

gives

error: no viable conversion from 'TempSignal<GG, const V, react::impl::FunctionOp<const V, react::AdditionOpFunctor<V, V>, std::shared_ptr<react::impl::SignalNode<GG, V> >, std::shared_ptr<react::impl::SignalNode<GG, V> > > >' to 'SignalT<V>' (aka 'react::Signal<GG, V>')
  SignalT<V> b = b1 + b2;
                 ^~~~~~~

help installing this on Raspberry Pi 3?

So I finally got TBB to work on Raspberry Pi, and I had to manually copy the header files into /usr/include, but it seems it wasn't enough.

Here is my current error
In file included from /usr/include/tbb/tbb_machine.h:247:0, from /usr/include/tbb/task.h:25, from /usr/include/tbb/task_group.h:24, from /home/pi/cpp.react-master/include/react/engine/PulsecountEngine.h:18, from /home/pi/cpp.react-master/src/engine/PulsecountEngine.cpp:7: /usr/include/tbb/machine/gcc_armv7.h:31:2: error: #error compilation requires an ARMv7-a architecture. #error compilation requires an ARMv7-a architecture. ^ In file included from /home/pi/cpp.react-master/include/react/engine/PulsecountEngine.h:22:0, from /home/pi/cpp.react-master/src/engine/PulsecountEngine.cpp:7: /home/pi/cpp.react-master/include/react/common/Containers.h: In instantiation of ‘react::impl::NodeBuffer<T, N>::NodeBuffer(react::impl::NodeBuffer<T, N>&, react::impl::SplitTag) [with T = react::impl::pulsecount::Node; unsigned int N = 8u]’: /home/pi/cpp.react-master/src/engine/PulsecountEngine.cpp:37:43: required from here /home/pi/cpp.react-master/include/react/common/Containers.h:120:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (auto i=0; i<split_size; i++) ^ CMakeFiles/CppReact.dir/build.make:54: recipe for target 'CMakeFiles/CppReact.dir/src/engine/PulsecountEngine.cpp.o' failed make[2]: *** [CMakeFiles/CppReact.dir/src/engine/PulsecountEngine.cpp.o] Error 1 CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/CppReact.dir/all' failed make[1]: *** [CMakeFiles/CppReact.dir/all] Error 2 Makefile:76: recipe for target 'all' failed make: *** [all] Error 2

Android and iOS compatibility

I'm really interested in this library for a mobile audio application I am working on. However before I begin trying to integrate it into my project, I would just like to know if it has been tested on Android, and iOS platforms?

Many thanks

No matching constructor for initialization of 'TimestampT' (aka 'time_point<std::chrono::high_resolution_clock>')

Compile failure on OS X (with our weird clocks)

Same as #6 which was closed I think prematurely.

He said that this fixes it PR #5 #5

bobsomers@4026735

Wonderful library, just what I needed ! Thanks

OS X 10.10.5
clang --version
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
build ❯ cmake ..
-- Boost version: 1.56.0
-- Found the following Boost libraries:
--   coroutine
--   context
--   system
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/crucial/Downloads/cpp.react/build
build ❯ make
[  7%] Building CXX object CMakeFiles/CppReact.dir/src/engine/PulsecountEngine.cpp.o
[ 15%] Building CXX object CMakeFiles/CppReact.dir/src/engine/SubtreeEngine.cpp.o
[ 23%] Building CXX object CMakeFiles/CppReact.dir/src/engine/ToposortEngine.cpp.o
[ 30%] Building CXX object CMakeFiles/CppReact.dir/src/logging/EventLog.cpp.o
/Users/crucial/Downloads/cpp.react/src/logging/EventLog.cpp:18:5: error: no matching constructor for initialization of 'TimestampT'
      (aka 'time_point<std::chrono::high_resolution_clock>')
    time_{ std::chrono::system_clock::now() },
    ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit copy constructor)
      not viable: no known conversion from 'time_point<std::__1::chrono::system_clock, duration<[...], ratio<[...], 1000000>>>' to 'const
      time_point<std::__1::chrono::steady_clock, duration<[...], ratio<[...], 1000000000>>>' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit move constructor)
      not viable: no known conversion from 'time_point<std::__1::chrono::system_clock, duration<[...], ratio<[...], 1000000>>>' to
      'time_point<std::__1::chrono::steady_clock, duration<[...], ratio<[...], 1000000000>>>' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:764:70: note: candidate constructor not viable: no known conversion
      from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const duration' (aka 'const std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> >')
      for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
                                                                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:769:5: note: candidate template ignored: could not match
      'std::__1::chrono::steady_clock' against 'std::__1::chrono::system_clock'
    time_point(const time_point<clock, _Duration2>& t,
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:763:61: note: candidate constructor not viable: requires 0
      arguments, but 1 was provided
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
                                                            ^
/Users/crucial/Downloads/cpp.react/src/logging/EventLog.cpp:30:5: error: no matching constructor for initialization of 'TimestampT'
      (aka 'time_point<std::chrono::high_resolution_clock>')
    time_{ std::chrono::system_clock::now() },
    ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit copy constructor)
      not viable: no known conversion from 'time_point<std::__1::chrono::system_clock, duration<[...], ratio<[...], 1000000>>>' to 'const
      time_point<std::__1::chrono::steady_clock, duration<[...], ratio<[...], 1000000000>>>' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit move constructor)
      not viable: no known conversion from 'time_point<std::__1::chrono::system_clock, duration<[...], ratio<[...], 1000000>>>' to
      'time_point<std::__1::chrono::steady_clock, duration<[...], ratio<[...], 1000000000>>>' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:764:70: note: candidate constructor not viable: no known conversion
      from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const duration' (aka 'const std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> >')
      for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
                                                                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:769:5: note: candidate template ignored: could not match
      'std::__1::chrono::steady_clock' against 'std::__1::chrono::system_clock'
    time_point(const time_point<clock, _Duration2>& t,
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:763:61: note: candidate constructor not viable: requires 0
      arguments, but 1 was provided
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
                                                            ^
/Users/crucial/Downloads/cpp.react/src/logging/EventLog.cpp:57:5: error: no matching constructor for initialization of 'TimestampT'
      (aka 'time_point<std::chrono::high_resolution_clock>')
    startTime_(std::chrono::system_clock::now())
    ^          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit copy constructor)
      not viable: no known conversion from 'time_point<std::__1::chrono::system_clock, duration<[...], ratio<[...], 1000000>>>' to 'const
      time_point<std::__1::chrono::steady_clock, duration<[...], ratio<[...], 1000000000>>>' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit move constructor)
      not viable: no known conversion from 'time_point<std::__1::chrono::system_clock, duration<[...], ratio<[...], 1000000>>>' to
      'time_point<std::__1::chrono::steady_clock, duration<[...], ratio<[...], 1000000000>>>' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:764:70: note: candidate constructor not viable: no known conversion
      from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const duration' (aka 'const std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> >')
      for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
                                                                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:769:5: note: candidate template ignored: could not match
      'std::__1::chrono::steady_clock' against 'std::__1::chrono::system_clock'
    time_point(const time_point<clock, _Duration2>& t,
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:763:61: note: candidate constructor not viable: requires 0
      arguments, but 1 was provided
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
                                                            ^
3 errors generated.
make[2]: *** [CMakeFiles/CppReact.dir/src/logging/EventLog.cpp.o] Error 1
make[1]: *** [CMakeFiles/CppReact.dir/all] Error 2
make: *** [all] Error 2

Paralell domain: signals doesn't seem to parallelize

Probably I misunderstand how parallelizing signals should be done. My issue is that the code below doesn't seem to parallelize. It is the example code from the README. As for the doCostlyOperation, it just sleeps for 1 second.

#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

#if defined(WIN32)
#include <windows.h>
#elif !defined(WIN32)
#include <unistd.h>
void Sleep(int ms) {
    usleep(1000*ms);
}
#endif

#include <react/Domain.h>
#include <react/Signal.h>
#include <react/Observer.h>


using namespace std;
using namespace react;

REACTIVE_DOMAIN(D, parallel)
USING_REACTIVE_DOMAIN(D)

int doCostlyOperation(int in) {
    std::cout << "do  " << in << std::endl;
    Sleep(1000);
    std::cout << "end " << in << std::endl;

    return in;
}

VarSignalT<int> in = MakeVar<D>(0);

SignalT<int> op1 = MakeSignal(in,
    [] (int in) {
        return doCostlyOperation(in);
    });

SignalT<int> op2 = MakeSignal(in,
    [] (int in) {
        return doCostlyOperation(in);
    });

// op1 and op2 can be re-calculated in parallel
SignalT<int> out = op1 + op2;


int main()
{
    in <<= 2;
}

The output I get is this:

do  0
end 0
do  0
end 0
do  2
end 2
do  2
end 2

Sleeps happen here:

do  0 # after this line  
end 0
do  0 # after this line
end 0
do  2 # after this line
end 2
do  2 # after this line
end 2

I would expect the code above to do some of the tasks in parallel, but currently it acts as if it were sequential.

include/react/event.h:106:62: error

include/react/event.h:106:62: error: storage class specifiers invalid in friend function declarations
friend static RET impl::CreateWrappedNode(ARGS&& ... args);

Is lazy node supported?

In the paper "Deprecating the Observer Pattern with Scala.React" there's a section "Strict vs Lazy Nodes", quoting from the paper:

Lazy nodes are notified by their dependencies eagerly,
but validated only when queried

My simple test showed that C++React evaluates the nodes when notified even though no one queries.
Is lazy node implemented? If not, is there any plan? or is it impossible for C++React?

compile error on osx with clang

Hey,
trying to compile cpp.react with clang 3.5.1 or clang 3.4.2 on OSX 10.9.5 shows the following error:

/Path/EventLog.cpp:18 
/Path/EventLog.cpp:18:5:  
error: no matching constructor for initialization of 'TimestampT' (aka 'time_point<std::chrono::high_resolution_clock>')
:5: error: no matching constructor for initialization of 'TimestampT' (aka 'time_point<std::chrono::high_resolution_clock>')
    time_{ std::chrono::system_clock::now() },
    ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    time_{ std::chrono::system_clock::now() },
    ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:29: note: 29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> > > &' for 1st argument
candidate constructor (the implicit copy constructor) not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> > > &' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^

/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> > > &&' for 1st argument
:29: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> > > &&' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^

/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:764/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:764:70: :70: note: candidate constructor not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const duration' (aka 'const std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> >') for 1st argument
note: candidate constructor not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const duration' (aka 'const std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> >') for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
                                                                     ^
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
                                                                     ^
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:769:5: /usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:769:5: note: candidate template ignored: could not match 'std::__1::chrono::steady_clock' against 'std::__1::chrono::system_clock'
note: candidate template ignored: could not match 'std::__1::chrono::steady_clock' against 'std::__1::chrono::system_clock'
    time_point(const time_point<clock, _Duration2>& t,
    ^
    time_point(const time_point<clock, _Duration2>& t,
    ^
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:763:61: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:763:61: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
                                                            ^    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
                                                            ^

/Users/lx/Documents/Text/Code/C_Languages/_frameworks/cpp.react/src/logging/EventLog.cpp:30/Users/lx/Documents/Text/Code/C_Languages/_frameworks/cpp.react/src/logging/EventLog.cpp:30:5: error: :5: error: no matching constructor for initialization of 'TimestampT' (aka 'time_point<std::chrono::high_resolution_clock>')
no matching constructor for initialization of 'TimestampT' (aka 'time_point<std::chrono::high_resolution_clock>')
    time_{ std::chrono::system_clock::now() },
    ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    time_{ std::chrono::system_clock::now() },
    ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:29: note: 29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> > > &' for 1st argument
candidate constructor (the implicit copy constructor) not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> > > &' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^

/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> > > &&' for 1st argument
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> > > &&' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^

/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:764:70: /usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:764:70: note: candidate constructor not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const duration' (aka 'const std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> >') for 1st argument
note: candidate constructor not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const duration' (aka 'const std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> >') for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
                                                                     ^    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
                                                                     ^

/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:769:/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:769:5: note: 5: note: candidate template ignored: could not match 'std::__1::chrono::steady_clock' against 'std::__1::chrono::system_clock'
candidate template ignored: could not match 'std::__1::chrono::steady_clock' against 'std::__1::chrono::system_clock'
    time_point(const time_point<clock, _Duration2>& t,
    ^    time_point(const time_point<clock, _Duration2>& t,
    ^
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:763:61:
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:763:61: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
 note: candidate constructor not viable: requires 0 arguments, but 1 was provided
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
                                                            ^    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
                                                            ^

/Users/lx/Documents/Text/Code/C_Languages/_frameworks/cpp.react/src/logging/EventLog.cpp:57:5: error: no matching constructor for initialization of 'TimestampT' (aka 'time_point<std::chrono::high_resolution_clock>')
/Users/lx/Documents/Text/Code/C_Languages/_frameworks/cpp.react/src/logging/EventLog.cpp:57:5: error: no matching constructor for initialization of 'TimestampT' (aka 'time_point<std::chrono::high_resolution_clock>')
    startTime_(std::chrono::system_clock::now())
    ^          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    startTime_(std::chrono::system_clock::now())
    ^          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'time_point<std::__1::chrono::system_clock, duration<[...], ratio<[...], 1000000>>>' to 'const time_point<std::__1::chrono::steady_clock, duration<[...], ratio<[...], 1000000000>>>' for 1st argument
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'time_point<std::__1::chrono::system_clock, duration<[...], ratio<[...], 1000000>>>' to 'const time_point<std::__1::chrono::steady_clock, duration<[...], ratio<[...], 1000000000>>>' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'time_point<std::__1::chrono::system_clock, duration<[...], ratio<[...], 1000000>>>' to 'time_point<std::__1::chrono::steady_clock, duration<[...], ratio<[...], 1000000000>>>' for 1st argument
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:750:29: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'time_point<std::__1::chrono::system_clock, duration<[...], ratio<[...], 1000000>>>' to 'time_point<std::__1::chrono::steady_clock, duration<[...], ratio<[...], 1000000000>>>' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^
class _LIBCPP_TYPE_VIS_ONLY time_point
                            ^
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:764:70: note/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:764:70: note: candidate constructor not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const duration' (aka 'const std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> >') for 1st argument
: candidate constructor not viable: no known conversion from 'time_point' (aka 'time_point<std::__1::chrono::system_clock>') to 'const duration' (aka 'const std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000000> >') for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
                                                                     ^
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:769:5: note:     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
                                                                     ^
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:769:5: note: candidate template ignored: could not match 'std::__1::chrono::steady_clock' against 'std::__1::chrono::system_clock'
candidate template ignored: could not match 'std::__1::chrono::steady_clock' against 'std::__1::chrono::system_clock'
    time_point(const time_point<clock, _Duration2>& t,
    ^
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:    time_point(const time_point<clock, _Duration2>& t,
    ^
/usr/local/Cellar/llvm/3.5.1/bin/../include/c++/v1/chrono:763:61: 763:61: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
note: candidate constructor not viable: requires 0 arguments, but 1 was provided
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
                                                            ^
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
                                                            ^
3 errors generated.
3 errors generated.
make[2]: make[2]: *** [CMakeFiles/CppReact.dir/src/logging/EventLog.cpp.o] Error 1
*** [CMakeFiles/CppReact.dir/src/logging/EventLog.cpp.o] Error 1
make[1]: *** [CMakeFiles/CppReact.dir/all] Error 2make[1]: *** [CMakeFiles/CppReact.dir/all] Error 2

Btw. compiling with gcc4.9 works with no problems. Any idea how I could get this working with clang?

Question: bind/unbind signal or event observer

It is not clear to me, how one can bind/unbind signal or event observer.

For example. I need to load a page. Page load took time.
When I start loading, I bind observer to work finish event/signal. Then, when work is done - I want to unbind observer. Then, I might need to load page again.

The nearest I found in the doc - is Observer.Detach() . But how to bind it again, is not clear to me.


And the second question - when the event queue clears?
How, for example, I can implement observer to left AND right mouse click (or double click)?
There will be definitely some delay between left and right MOUSE_DOWN event

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.