-/* Copyright (c) 2015-2016. The SimGrid Team.
+/* Copyright (c) 2015-2017. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include <stdexcept>
#include <type_traits>
#include <utility>
+#include <xbt/ex.h>
namespace simgrid {
namespace xbt {
exception,
};
public:
- Result() {}
+ Result() { /* Nothing to do */}
~Result() { this->reset(); }
// Copy (if T is copyable) and move:
switch (that.status_) {
case ResultStatus::invalid:
break;
- case ResultStatus::valid:
+ case ResultStatus::value:
new (&value_) T(that.value);
break;
case ResultStatus::exception:
new (&exception_) T(that.exception);
break;
+ default:
+ THROW_IMPOSSIBLE;
}
return *this;
}
switch (that.status_) {
case ResultStatus::invalid:
break;
- case ResultStatus::valid:
+ case ResultStatus::value:
new (&value_) T(std::move(that.value));
that.value.~T();
break;
new (&exception_) T(std::move(that.exception));
that.exception.~exception_ptr();
break;
+ default:
+ THROW_IMPOSSIBLE;
}
that.status_ = ResultStatus::invalid;
return *this;
case ResultStatus::exception:
exception_.~exception_ptr();
break;
+ default:
+ THROW_IMPOSSIBLE;
}
status_ = ResultStatus::invalid;
}
T get()
{
switch (status_) {
- case ResultStatus::invalid:
- default:
- throw std::logic_error("Invalid result");
case ResultStatus::value: {
T value = std::move(value_);
value_.~T();
std::rethrow_exception(std::move(exception));
break;
}
+ default:
+ throw std::logic_error("Invalid result");
}
}
private: