3 回答
TA贡献1744条经验 获得超4个赞
is_base_of
template<typename T>class ObservableList {
BOOST_STATIC_ASSERT((is_base_of<List, T>::value)); //Yes, the double parentheses are needed, otherwise the comma will be seen as macro argument separator
...};template<typename T> class my_template; // Declare, but don't define// int is a valid typetemplate<> class my_template<int> {
...};// All pointer types are validtemplate<typename T> class my_template<T*> {
...};// All other types are invalid, and will cause linker error messages.TA贡献1827条经验 获得超8个赞
<type_traits>:
#include <type_traits>template<typename T>class observable_list {
static_assert(std::is_base_of<list, T>::value, "T must inherit from list");
// code here..};observable_listconst_iteratorbeginendconst_iteratorlistlistobservable_list.
static_assert.
#include <type_traits>template<typename...>struct void_ {
using type = void;};template<typename... Args>using Void = typename void_<Args...>::type;template<typename T, typename = void>struct has_const_iterator : std::false_type {};template<typename T>struct has_const_iterator<T, Void<typename T::const_iterator>> : std::true_type {};struct has_begin_end_impl {
template<typename T, typename Begin = decltype(std::declval<const T&>().begin()),
typename End = decltype(std::declval<const T&>().end())>
static std::true_type test(int);
template<typename...>
static std::false_type test(...);};template<typename T>struct has_begin_end : decltype(has_begin_end_impl::test<T>(0)) {};template<typename T>class observable_list {
static_assert(has_const_iterator<T>::value, "Must have a const_iterator typedef");
static_assert(has_begin_end<T>::value, "Must have begin and end member functions");
// code here...};TA贡献1725条经验 获得超8个赞
int
static_assert
- 3 回答
- 0 关注
- 580 浏览
添加回答
举报
