Skip to content

future's then doesn't fully support mutable lambdas yet #287

@fosterbrereton

Description

@fosterbrereton

Here's an example that produces a compiler error:

#include <stlab/concurrency/future.hpp>
#include <stlab/concurrency/immediate_executor.hpp>
#include <stlab/concurrency/default_executor.hpp>

#include <iostream>

using namespace stlab;
using namespace std;

future<int> placeholder();
void do_some_thing(int, int);

template <typename Func, typename ErrFunc>
void long_send(Func &&func, ErrFunc &&err_func) {
  placeholder() // returns an stlab::future<token_type>
      .then(stlab::default_executor,
            [_f = std::forward<Func>(func),
             _error = std::forward<ErrFunc>(err_func)](auto token) mutable {
              try {
                do_some_thing(token, std::move(_f)());
              } catch (const std::exception &error) {
                std::move(_error)(error.what());
              } catch (...) {
                std::move(_error)("Error: unknown");
              }
            })
      .detach();
}

int main() {
    long_send([]{ return 42; },[](const auto& e){});
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions