mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Add type_list functionality to etl::visitor using etl::visitor_from_type_list
This commit is contained in:
parent
a61980660f
commit
bde8747be8
@ -84,23 +84,20 @@ namespace etl
|
||||
virtual void accept(T1&) = 0;
|
||||
};
|
||||
|
||||
//*****************************************************************
|
||||
/// The visitable class for an etl::type_list.
|
||||
/// Expands the type_list into the existing variadic visitable.
|
||||
///\ingroup visitor
|
||||
//*****************************************************************
|
||||
//***************************************************************************
|
||||
/// Helper to turn etl::type_list<TTypes...> into etl::visitable<TTypes...>
|
||||
template <typename TList>
|
||||
struct visitable_from_type_list;
|
||||
|
||||
template <typename... TTypes>
|
||||
class visitable<etl::type_list<TTypes...>> : public visitable<TTypes...>
|
||||
struct visitable_from_type_list<etl::type_list<TTypes...>>
|
||||
{
|
||||
ETL_STATIC_ASSERT(sizeof...(TTypes) != 0, "etl::type_list must not be empty");
|
||||
|
||||
public:
|
||||
|
||||
using type_list = etl::type_list<TTypes...>;
|
||||
|
||||
using visitable<TTypes...>::accept;
|
||||
using type = etl::visitable<TTypes...>;
|
||||
};
|
||||
|
||||
template <typename TTypeList>
|
||||
using visitable_from_type_list_t = typename visitable_from_type_list<TTypeList>::type;
|
||||
|
||||
#else
|
||||
|
||||
//*****************************************************************
|
||||
|
||||
@ -110,6 +110,7 @@ SOFTWARE.
|
||||
#define ETL_FLAT_SET_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_FLAT_MULTISET_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_VARIANT_POOL_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_VISITOR_FORCE_CPP03_IMPLEMENTATION
|
||||
#endif
|
||||
|
||||
#if defined(ETL_FORCE_TEST_CPP11)
|
||||
|
||||
@ -746,6 +746,19 @@ namespace
|
||||
CHECK_FALSE(etl::is_visitor<NotVisitor>::value);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(ETL_VISITOR_FORCE_CPP03_IMPLEMENTATION)
|
||||
//*************************************************************************
|
||||
TEST(test_visitable_from_type_list)
|
||||
{
|
||||
using Visitable1 = etl::visitable<DrawVisitorType, LogVisitorType>;
|
||||
|
||||
using TypeList = etl::type_list<DrawVisitorType, LogVisitorType>;
|
||||
using Visitable2 = etl::visitable_from_type_list_t<TypeList>;
|
||||
|
||||
CHECK_TRUE((std::is_same<Visitable1, Visitable2>::value));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user