Skip to content

Commit 3e62cae

Browse files
committed
AK: Add Variant::unsafe_get()
This performs no validation and no verifications on release. only useful when you've already verified the type by external means.
1 parent d8ea9e6 commit 3e62cae

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

AK/Variant.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ struct Variant
355355
return nullptr;
356356
}
357357

358+
template<typename T>
359+
T& unsafe_get()
360+
requires(can_contain<T>())
361+
{
362+
ASSERT(has<T>());
363+
return *bit_cast<T*>(&m_data);
364+
}
365+
358366
template<typename T>
359367
T& get()
360368
requires(can_contain<T>())
@@ -380,6 +388,14 @@ struct Variant
380388
return *bit_cast<T const*>(&m_data);
381389
}
382390

391+
template<typename T>
392+
T const& unsafe_get() const
393+
requires(can_contain<T>())
394+
{
395+
ASSERT(has<T>());
396+
return *bit_cast<T const*>(&m_data);
397+
}
398+
383399
template<typename T>
384400
[[nodiscard]] bool has() const
385401
requires(can_contain<T>())

0 commit comments

Comments
 (0)