tgockel / zookeeper-cpp

A ZooKeeper client for C++.
http://tgockel.github.io/zookeeper-cpp/
Apache License 2.0
148 stars 40 forks source link

error: ‘zk::future<zk::get_result> {aka class std::future<zk::get_result>}’ has no member named ‘then’ #107

Open zg9uagfv opened 5 years ago

zg9uagfv commented 5 years ago

Env:

ubuntu18.04
g++ (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0

Code:

int main()
{
    // Start a ZK server running on localhost (not needed if you just want a client, but great for testing and
    // demonstration purposes).
    zk::server::server server(zk::server::configuration::make_minimal("zk-data", 2181));

    // zk::client::connect returns a future<zk::client>, which is delivered when the connection is established.
    auto client = zk::client::connect("zk://127.0.0.1:2181").get();

    // get_result has a zk::buffer and zk::stat.
    client.get("/foo/bar").then(print_thing<zk::get_result>);
    return 0x00;
}

Compile Command: g++ --std=c++17 -I ~/github/zookeeper-cpp/src/ test.cpp

Compile Error: test.cpp: In function ‘int main()’: test.cpp:37:28: error: ‘zk::future<zk::get_result> {aka class std::future<zk::get_result>}’ has no member named ‘then’ client.get("/foo/bar").then(print_thing<zk::get_result>);

thanks a lot!

tgockel commented 5 years ago

The then function comes from the proposed std::experimental::future::then, which is still not in C++17. I was hoping the C++ Standard would catch up to my documentation. In the future, there will be a workaround to set ZKPP_FUTURE_USE_STD_EXPERIMENTAL to 1. This requires two changes:

  1. When building the library, cmake -DZKPP_BUILD_SETTING_FUTURE=STD_EXPERIMENTAL ..
  2. When using it in your own project, #define ZKPP_FUTURE_USE_STD_EXPERIMENTAL 1

NOTE: This will not work unless you have <experimental/future> implemented by your Standard Library implementation, which I don't know of any implementation this is true in. boost::future has a then implementation, but I haven't added ZKPP_BUILD_SETTING_FUTURE=BOOST_THREAD equivalent (yet).

tuxflo commented 3 years ago

Sorry for bumping this old issue, but I'm facing the same problem. I saw that PR #112 was merged, but I can't figure out on how to use the .then of boost, since it seems to expect more than one argument. Is there a minimal working example anywhere?

robmarano commented 8 months ago

+1

Sorry for bumping this old issue, but I'm facing the same problem. I saw that PR #112 was merged, but I can't figure out on how to use the .then of boost, since it seems to expect more than one argument. Is there a minimal working example anywhere?