zookeeper-cpp icon indicating copy to clipboard operation
zookeeper-cpp copied to clipboard

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

Open zg9uagfv opened this issue 5 years ago • 3 comments

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!

zg9uagfv avatar Jul 01 '19 07:07 zg9uagfv

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).

tgockel avatar Jul 01 '19 17:07 tgockel

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?

tuxflo avatar Aug 04 '21 09:08 tuxflo

+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?

robmarano avatar Dec 12 '23 21:12 robmarano