mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added etl::visitor_from_type_list
This commit is contained in:
parent
3826e2ab2e
commit
58619ec675
@ -205,21 +205,20 @@ namespace etl
|
||||
virtual void visit(T1) = 0;
|
||||
};
|
||||
|
||||
//*****************************************************************
|
||||
/// The visitor class for an etl::type_list.
|
||||
/// Expands the type_list into the existing variadic visitor.
|
||||
///\ingroup visitor
|
||||
//*****************************************************************
|
||||
//***************************************************************************
|
||||
/// Helper to turn etl::type_list<TTypes...> into etl::visitor<TTypes...>
|
||||
template <typename TList>
|
||||
struct visitor_from_type_list;
|
||||
|
||||
template <typename... TTypes>
|
||||
class visitor<etl::type_list<TTypes...>> : public visitor<TTypes...>
|
||||
struct visitor_from_type_list<etl::type_list<TTypes...>>
|
||||
{
|
||||
ETL_STATIC_ASSERT(sizeof...(TTypes) != 0, "etl::type_list must not be empty");
|
||||
|
||||
public:
|
||||
|
||||
using visitor<TTypes...>::visit;
|
||||
using type = etl::visitor<TTypes...>;
|
||||
};
|
||||
|
||||
template <typename TTypeList>
|
||||
using visitor_from_type_list_t = typename visitor_from_type_list<TTypeList>::type;
|
||||
|
||||
#else
|
||||
|
||||
//*****************************************************************
|
||||
|
||||
@ -747,6 +747,19 @@ namespace
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(ETL_VISITOR_FORCE_CPP03_IMPLEMENTATION)
|
||||
//*************************************************************************
|
||||
TEST(test_visitor_from_type_list)
|
||||
{
|
||||
using Visitor1 = etl::visitor<Square&, Circle&, const Triangle&>;
|
||||
|
||||
using TypeList = etl::type_list<Square&, Circle&, const Triangle&>;
|
||||
using Visitor2 = etl::visitor_from_type_list_t<TypeList>;
|
||||
|
||||
CHECK_TRUE((std::is_same<Visitor1, Visitor2>::value));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(ETL_VISITOR_FORCE_CPP03_IMPLEMENTATION)
|
||||
//*************************************************************************
|
||||
TEST(test_visitable_from_type_list)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user