No need to re-invent wheels. It would be nice if we could have used std::is_base_of,
but that doesn't work because we don't know for sure which ones of the
possible BlockVectorBase<T> classes is the right base class, given that we don't
know T.
#include <cmath>
#include <cstddef>
#include <iterator>
+#include <type_traits>
#include <vector>
DEAL_II_NAMESPACE_OPEN
struct IsBlockVector
{
private:
- struct yes_type
- {
- char c[1];
- };
- struct no_type
- {
- char c[2];
- };
-
/**
* Overload returning true if the class is derived from BlockVectorBase,
* which is what block vectors do.
*/
template <typename T>
- static yes_type
+ static std::true_type
check_for_block_vector(const BlockVectorBase<T> *);
/**
* Catch all for all other potential vector types that are not block
* matrices.
*/
- static no_type
+ static std::false_type
check_for_block_vector(...);
public:
* derived from BlockVectorBase<T>).
*/
static const bool value =
- (sizeof(check_for_block_vector(static_cast<VectorType *>(nullptr))) ==
- sizeof(yes_type));
+ std::is_same<decltype(check_for_block_vector(std::declval<VectorType *>())),
+ std::true_type>::value;
};
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams