Skip to content
Snippets Groups Projects
Commit 9cf16a91 authored by Jakub Klinkovský's avatar Jakub Klinkovský Committed by Tomáš Oberhuber
Browse files

Fixed HasConstexprGetSizeMethod trait class to work with scalar types

parent 0e9e9c89
No related branches found
No related tags found
1 merge request!41Tutorials
...@@ -127,25 +127,35 @@ struct HasConstexprGetSizeMethod ...@@ -127,25 +127,35 @@ struct HasConstexprGetSizeMethod
{ {
private: private:
// implementation adopted from here: https://stackoverflow.com/a/50169108 // implementation adopted from here: https://stackoverflow.com/a/50169108
template< bool hasGetSize = HasGetSizeMethod< T >::value, typename = void >
// disable nvcc warning: invalid narrowing conversion from "unsigned int" to "int" struct impl
// (the implementation is based on the conversion) {
#ifdef __NVCC__ // disable nvcc warning: invalid narrowing conversion from "unsigned int" to "int"
#pragma push // (the implementation is based on the conversion)
#pragma diag_suppress 2361 #ifdef __NVCC__
#endif #pragma push
template< typename M, M method > #pragma diag_suppress 2361
static constexpr std::true_type is_constexpr_impl( decltype(int{((*method)(), 0U)}) ); #endif
#ifdef __NVCC__ template< typename M, M method >
#pragma pop static constexpr std::true_type is_constexpr_impl( decltype(int{((*method)(), 0U)}) );
#endif #ifdef __NVCC__
#pragma pop
template< typename M, M method > #endif
static constexpr std::false_type is_constexpr_impl(...);
template< typename M, M method >
using type = decltype(is_constexpr_impl< decltype(&T::getSize), &T::getSize >(0)); static constexpr std::false_type is_constexpr_impl(...);
// 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 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: public:
static constexpr bool value = type::value; static constexpr bool value = type::value;
...@@ -160,7 +170,6 @@ public: ...@@ -160,7 +170,6 @@ public:
template< typename T > template< typename T >
struct IsStaticArrayType struct IsStaticArrayType
: public std::integral_constant< bool, : public std::integral_constant< bool,
HasGetSizeMethod< T >::value &&
HasConstexprGetSizeMethod< T >::value && HasConstexprGetSizeMethod< T >::value &&
HasSubscriptOperator< T >::value > HasSubscriptOperator< T >::value >
{}; {};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment