The code in this question uses the Either<> implementation found here: https://github.com/LoopPerfect/neither. To be clear, I doubt that this is a problem with this specific library, otherwise I would have created an issue there.
The following snippet works as expected:
std::future<std::string> f = std::async(std::launch::async, []()
{
return "test";
}
std::cout << f.get() << std::endl;
And the following generates a segmentation fault:
std::future<neither::Either<int, std::string>> f = std::async(std::launch::async, []()
{
return neither::Either<int, std::string>(neither::right(std::string("test")));
});
neither::Either<int, std::string> v = f.get(); // Segmentation fault
std::cout << v.right().value << std::endl;
Returning left(-1) works, as does neither::Either<int, int> for both left() and right(). I know that std::future::get might generate a segfault is that you've called it twice, in which case std::future::valid will return false just prior to calling get, but valid returns true.
Is there something I'm missing here?