Can static_assert check if a type is a vector? IE, an int
would raise the assertion, whereas a vector<int>
would not.
I'm thinking of something along the lines of:
static_assert(decltype(T) == std::vector, "Some error")
To check if type of given vector is character in R, call is. character() function and pass the vector as argument to this function. If the given vector is of type character, then is. character() returns TRUE, or else, it returns FALSE.
If the condition is true, the static_assert declaration has no effect. If the condition is false, the assertion fails, the compiler displays the message in string_literal parameter and the compilation fails with an error.
static_assert is a keyword defined in the <assert. h> header. It is available in the C11 version of C. static_assert is used to ensure that a condition is true when the code is compiled. The condition must be a constant expression.
Yes. Consider the following meta function:
#include <stdio.h> #include <vector> template <class N> struct is_vector { static const int value = 0; }; template <class N, class A> struct is_vector<std::vector<N, A> > { static const int value = 1; }; int main() { printf("is_vector<int>: %d\n", is_vector<int>::value); printf("is_vector<vector<int> >: %d\n", is_vector<std::vector<int> >::value); }
Simply use that as your expression in static_assert
.
c++0x:
static_assert(std::is_same<T, std::vector<int>>::value, "Some Error");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With