mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Implement cm::static_reference_cast by declval
Previously, cm::static_reference_cast used invoke_result_t and took the address of O::get. This is not in complete conformance with standard. This MR changes the implementation to use std::declval<O>.get() which is always well-defined.
This commit is contained in:

committed by
Brad King

parent
09507da00a
commit
d2f891288a
@@ -12,18 +12,19 @@
|
||||
|
||||
namespace cm {
|
||||
|
||||
template <typename T, typename O,
|
||||
cm::enable_if_t<
|
||||
std::is_pointer<cm::invoke_result_t<decltype(&O::get), O>>::value,
|
||||
int> = 0>
|
||||
template <
|
||||
typename T, typename O,
|
||||
cm::enable_if_t<std::is_pointer<decltype(std::declval<O>().get())>::value,
|
||||
int> = 0>
|
||||
T& static_reference_cast(O& item)
|
||||
{
|
||||
return *(static_cast<T*>(item.get()));
|
||||
}
|
||||
template <typename T, typename O,
|
||||
cm::enable_if_t<
|
||||
std::is_pointer<cm::invoke_result_t<decltype(&O::get), O>>::value,
|
||||
int> = 0>
|
||||
|
||||
template <
|
||||
typename T, typename O,
|
||||
cm::enable_if_t<std::is_pointer<decltype(std::declval<O>().get())>::value,
|
||||
int> = 0>
|
||||
T& dynamic_reference_cast(O& item)
|
||||
{
|
||||
auto p = dynamic_cast<T*>(item.get());
|
||||
|
Reference in New Issue
Block a user