const T& get() const { if (!isSome()) { std::string errorMessage = "Result::get() but state == "; if (isError()) { errorMessage += "ERROR: " + data.error(); } else if (isNone()) { errorMessage += "NONE"; } ABORT(errorMessage); } return data.get().get(); }
Option<T>& operator=(Option<T>&& that) { if (this != &that) { if (isSome()) { t.~T(); } state = std::move(that.state); if (that.isSome()) { new (&t) T(std::move(that.t)); } } return *this; }
Option<T>& operator=(const Option<T>& that) { if (this != &that) { if (isSome()) { t.~T(); } state = that.state; if (that.isSome()) { new (&t) T(that.t); } } return *this; }
static void getString(CacheAndIndex* cacheAndIndex) { for (int i = 0; i < NUM_ITERATIONS; i++) { auto str = STRINGS[cacheAndIndex->index % NUM_STRINGS]; auto dupe = js::DuplicateString(str); MOZ_RELEASE_ASSERT(dupe); auto deduped = cacheAndIndex->cache->getOrCreate(mozilla::Move(dupe), js_strlen(str)); MOZ_RELEASE_ASSERT(deduped.isSome()); MOZ_RELEASE_ASSERT(js_strcmp(str, deduped->chars()) == 0); { auto cloned = deduped->clone(); // We should be de-duplicating and giving back the same string. MOZ_RELEASE_ASSERT(deduped->chars() == cloned.chars()); } } js_delete(cacheAndIndex); }
~Option() { if (isSome()) { t.~T(); } }
bool operator==(const T& that) const { return isSome() && t == that; }
bool operator==(const Option<T>& that) const { return (isNone() && that.isNone()) || (isSome() && that.isSome() && t == that.t); }
const T&& get() const && { assert(isSome()); return std::move(t); }
T& get() & { assert(isSome()); return t; }
const T& get() const & { assert(isSome()); return t; }