get_if may not be called if there is more than one match

This commit is contained in:
Hans Dembinski
2019-06-02 21:35:27 +02:00
parent de37af2a94
commit 4e7febfa2c

View File

@@ -130,12 +130,14 @@ public:
template <class T>
T* get_if() noexcept {
static_assert(mp11::mp_count<variant, T>::value <= 1, "no unique match for T");
constexpr auto i = mp11::mp_find<variant, T>{};
return i == index_ ? &ref<T>() : nullptr;
}
template <class T>
const T* get_if() const noexcept {
static_assert(mp11::mp_count<variant, T>::value <= 1, "no unique match for T");
constexpr auto i = mp11::mp_find<variant, T>{};
return i == index_ ? &ref<T>() : nullptr;
}