Commit 9cf16a91 authored by Jakub Klinkovský's avatar Jakub Klinkovský Committed by Tomáš Oberhuber

Fixed HasConstexprGetSizeMethod trait class to work with scalar types

parent 0e9e9c89
......@@ -127,25 +127,35 @@ struct HasConstexprGetSizeMethod
{
private:
// implementation adopted from here: https://stackoverflow.com/a/50169108
// disable nvcc warning: invalid narrowing conversion from "unsigned int" to "int"
// (the implementation is based on the conversion)
#ifdef __NVCC__
#pragma push
#pragma diag_suppress 2361
#endif
template< typename M, M method >
static constexpr std::true_type is_constexpr_impl( decltype(int{((*method)(), 0U)}) );
#ifdef __NVCC__
#pragma pop
#endif
template< typename M, M method >
static constexpr std::false_type is_constexpr_impl(...);
using type = decltype(is_constexpr_impl< decltype(&T::getSize), &T::getSize >(0));
// TODO: this does not work for integral types because T::getSize does not exist
// error #276: name followed by "::" must be a class or namespace name
template< bool hasGetSize = HasGetSizeMethod< T >::value, typename = void >
struct impl
{
// disable nvcc warning: invalid narrowing conversion from "unsigned int" to "int"
// (the implementation is based on the conversion)
#ifdef __NVCC__
#pragma push
#pragma diag_suppress 2361
#endif
template< typename M, M method >
static constexpr std::true_type is_constexpr_impl( decltype(int{((*method)(), 0U)}) );
#ifdef __NVCC__
#pragma pop
#endif
template< typename M, M method >
static constexpr std::false_type is_constexpr_impl(...);
using type = decltype(is_constexpr_impl< decltype(&T::getSize), &T::getSize >(0));
};
// specialization for types which don't have getSize() method at all
template< typename _ >
struct impl< false, _ >
{
using type = std::false_type;
};
using type = typename impl<>::type;
public:
static constexpr bool value = type::value;
......@@ -160,7 +170,6 @@ public:
template< typename T >
struct IsStaticArrayType
: public std::integral_constant< bool,
HasGetSizeMethod< T >::value &&
HasConstexprGetSizeMethod< T >::value &&
HasSubscriptOperator< T >::value >
{};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment