Refactored visitor and variant to allow const variants and fix passing references to visitors

This commit is contained in:
John Wellbelove 2023-06-11 16:23:43 +01:00
parent 83f439628b
commit 177299977d
5 changed files with 456 additions and 391 deletions

1
.gitignore vendored
View File

@ -376,3 +376,4 @@ test/syntax_check/c++20/bclang
test/syntax_check/c++11/bgcc
test/syntax_check/c++17/bgcc
test/syntax_check/c++20/bgcc
test/vs2022/Debug MSVC C++17

View File

@ -825,7 +825,9 @@ namespace etl
//***************************************************************************
/// Accept an etl::visitor.
//***************************************************************************
void accept(etl::visitor<TTypes...>& v)
template <typename TVisitor>
etl::enable_if_t<etl::is_visitor<TVisitor>::value, void>
accept(TVisitor& v)
{
#if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11)
do_visitor(v, etl::make_index_sequence<sizeof...(TTypes)>{});
@ -837,7 +839,9 @@ namespace etl
//***************************************************************************
/// Accept an etl::visitor.
//***************************************************************************
void accept(etl::visitor<TTypes...>& v) const
template <typename TVisitor>
etl::enable_if_t<etl::is_visitor<TVisitor>::value, void>
accept(TVisitor& v) const
{
#if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11)
do_visitor(v, etl::make_index_sequence<sizeof...(TTypes)>{});
@ -850,7 +854,7 @@ namespace etl
/// Accept a generic functor.
//***************************************************************************
template <typename TVisitor>
etl::enable_if_t<!etl::is_base_of<etl::visitor<TTypes...>, TVisitor>::value, void>
etl::enable_if_t<!etl::is_visitor<TVisitor>::value, void>
accept(TVisitor& v)
{
#if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11)
@ -864,7 +868,7 @@ namespace etl
/// Accept a generic functor.
//***************************************************************************
template <typename TVisitor>
etl::enable_if_t<!etl::is_base_of<etl::visitor<TTypes...>, TVisitor>::value, void>
etl::enable_if_t<!etl::is_visitor<TVisitor>::value, void>
accept(TVisitor& v) const
{
#if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11)
@ -1018,41 +1022,41 @@ namespace etl
{
switch (index())
{
case 0: { auto arg = etl::get<0>(*this); visitor.visit(arg); break; }
case 1: { auto arg = etl::get<1>(*this); visitor.visit(arg); break; }
case 2: { auto arg = etl::get<2>(*this); visitor.visit(arg); break; }
case 3: { auto arg = etl::get<3>(*this); visitor.visit(arg); break; }
case 4: { auto arg = etl::get<4>(*this); visitor.visit(arg); break; }
case 5: { auto arg = etl::get<5>(*this); visitor.visit(arg); break; }
case 6: { auto arg = etl::get<6>(*this); visitor.visit(arg); break; }
case 7: { auto arg = etl::get<7>(*this); visitor.visit(arg); break; }
case 0: { visitor.visit(etl::get<0>(*this)); break; }
case 1: { visitor.visit(etl::get<1>(*this)); break; }
case 2: { visitor.visit(etl::get<2>(*this)); break; }
case 3: { visitor.visit(etl::get<3>(*this)); break; }
case 4: { visitor.visit(etl::get<4>(*this)); break; }
case 5: { visitor.visit(etl::get<5>(*this)); break; }
case 6: { visitor.visit(etl::get<6>(*this)); break; }
case 7: { visitor.visit(etl::get<7>(*this)); break; }
#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES)
case 8: { auto arg = etl::get<8>(*this); visitor.visit(arg); break; }
case 9: { auto arg = etl::get<9>(*this); visitor.visit(arg); break; }
case 10: { auto arg = etl::get<10>(*this); visitor.visit(arg); break; }
case 11: { auto arg = etl::get<11>(*this); visitor.visit(arg); break; }
case 12: { auto arg = etl::get<12>(*this); visitor.visit(arg); break; }
case 13: { auto arg = etl::get<13>(*this); visitor.visit(arg); break; }
case 14: { auto arg = etl::get<14>(*this); visitor.visit(arg); break; }
case 15: { auto arg = etl::get<15>(*this); visitor.visit(arg); break; }
case 8: { visitor.visit(etl::get<8>(*this)); break; }
case 9: { visitor.visit(etl::get<9>(*this)); break; }
case 10: { visitor.visit(etl::get<10>(*this)); break; }
case 11: { visitor.visit(etl::get<11>(*this)); break; }
case 12: { visitor.visit(etl::get<12>(*this)); break; }
case 13: { visitor.visit(etl::get<13>(*this)); break; }
case 14: { visitor.visit(etl::get<14>(*this)); break; }
case 15: { visitor.visit(etl::get<15>(*this)); break; }
#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES)
case 16: { auto arg = etl::get<16>(*this); visitor.visit(arg); break; }
case 17: { auto arg = etl::get<17>(*this); visitor.visit(arg); break; }
case 18: { auto arg = etl::get<18>(*this); visitor.visit(arg); break; }
case 19: { auto arg = etl::get<19>(*this); visitor.visit(arg); break; }
case 20: { auto arg = etl::get<20>(*this); visitor.visit(arg); break; }
case 21: { auto arg = etl::get<21>(*this); visitor.visit(arg); break; }
case 22: { auto arg = etl::get<22>(*this); visitor.visit(arg); break; }
case 23: { auto arg = etl::get<23>(*this); visitor.visit(arg); break; }
case 16: { visitor.visit(etl::get<16>(*this)); break; }
case 17: { visitor.visit(etl::get<17>(*this)); break; }
case 18: { visitor.visit(etl::get<18>(*this)); break; }
case 19: { visitor.visit(etl::get<19>(*this)); break; }
case 20: { visitor.visit(etl::get<20>(*this)); break; }
case 21: { visitor.visit(etl::get<21>(*this)); break; }
case 22: { visitor.visit(etl::get<22>(*this)); break; }
case 23: { visitor.visit(etl::get<23>(*this)); break; }
#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES)
case 24: { auto arg = etl::get<24>(*this); visitor.visit(arg); break; }
case 25: { auto arg = etl::get<25>(*this); visitor.visit(arg); break; }
case 26: { auto arg = etl::get<26>(*this); visitor.visit(arg); break; }
case 27: { auto arg = etl::get<27>(*this); visitor.visit(arg); break; }
case 28: { auto arg = etl::get<28>(*this); visitor.visit(arg); break; }
case 29: { auto arg = etl::get<29>(*this); visitor.visit(arg); break; }
case 30: { auto arg = etl::get<30>(*this); visitor.visit(arg); break; }
case 31: { auto arg = etl::get<31>(*this); visitor.visit(arg); break; }
case 24: { visitor.visit(etl::get<24>(*this)); break; }
case 25: { visitor.visit(etl::get<25>(*this)); break; }
case 26: { visitor.visit(etl::get<26>(*this)); break; }
case 27: { visitor.visit(etl::get<27>(*this)); break; }
case 28: { visitor.visit(etl::get<28>(*this)); break; }
case 29: { visitor.visit(etl::get<29>(*this)); break; }
case 30: { visitor.visit(etl::get<30>(*this)); break; }
case 31: { visitor.visit(etl::get<31>(*this)); break; }
#endif
#endif
#endif
@ -1068,41 +1072,41 @@ namespace etl
{
switch (index())
{
case 0: { auto arg = etl::get<0>(*this); visitor.visit(arg); break; }
case 1: { auto arg = etl::get<1>(*this); visitor.visit(arg); break; }
case 2: { auto arg = etl::get<2>(*this); visitor.visit(arg); break; }
case 3: { auto arg = etl::get<3>(*this); visitor.visit(arg); break; }
case 4: { auto arg = etl::get<4>(*this); visitor.visit(arg); break; }
case 5: { auto arg = etl::get<5>(*this); visitor.visit(arg); break; }
case 6: { auto arg = etl::get<6>(*this); visitor.visit(arg); break; }
case 7: { auto arg = etl::get<7>(*this); visitor.visit(arg); break; }
case 0: { visitor.visit(etl::get<0>(*this)); break; }
case 1: { visitor.visit(etl::get<1>(*this)); break; }
case 2: { visitor.visit(etl::get<2>(*this)); break; }
case 3: { visitor.visit(etl::get<3>(*this)); break; }
case 4: { visitor.visit(etl::get<4>(*this)); break; }
case 5: { visitor.visit(etl::get<5>(*this)); break; }
case 6: { visitor.visit(etl::get<6>(*this)); break; }
case 7: { visitor.visit(etl::get<7>(*this)); break; }
#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES)
case 8: { auto arg = etl::get<8>(*this); visitor.visit(arg); break; }
case 9: { auto arg = etl::get<9>(*this); visitor.visit(arg); break; }
case 10: { auto arg = etl::get<10>(*this); visitor.visit(arg); break; }
case 11: { auto arg = etl::get<11>(*this); visitor.visit(arg); break; }
case 12: { auto arg = etl::get<12>(*this); visitor.visit(arg); break; }
case 13: { auto arg = etl::get<13>(*this); visitor.visit(arg); break; }
case 14: { auto arg = etl::get<14>(*this); visitor.visit(arg); break; }
case 15: { auto arg = etl::get<15>(*this); visitor.visit(arg); break; }
case 8: { visitor.visit(etl::get<8>(*this)); break; }
case 9: { visitor.visit(etl::get<9>(*this)); break; }
case 10: { visitor.visit(etl::get<10>(*this)); break; }
case 11: { visitor.visit(etl::get<11>(*this)); break; }
case 12: { visitor.visit(etl::get<12>(*this)); break; }
case 13: { visitor.visit(etl::get<13>(*this)); break; }
case 14: { visitor.visit(etl::get<14>(*this)); break; }
case 15: { visitor.visit(etl::get<15>(*this)); break; }
#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES)
case 16: { auto arg = etl::get<16>(*this); visitor.visit(arg); break; }
case 17: { auto arg = etl::get<17>(*this); visitor.visit(arg); break; }
case 18: { auto arg = etl::get<18>(*this); visitor.visit(arg); break; }
case 19: { auto arg = etl::get<19>(*this); visitor.visit(arg); break; }
case 20: { auto arg = etl::get<20>(*this); visitor.visit(arg); break; }
case 21: { auto arg = etl::get<21>(*this); visitor.visit(arg); break; }
case 22: { auto arg = etl::get<22>(*this); visitor.visit(arg); break; }
case 23: { auto arg = etl::get<23>(*this); visitor.visit(arg); break; }
case 16: { visitor.visit(etl::get<16>(*this)); break; }
case 17: { visitor.visit(etl::get<17>(*this)); break; }
case 18: { visitor.visit(etl::get<18>(*this)); break; }
case 19: { visitor.visit(etl::get<19>(*this)); break; }
case 20: { visitor.visit(etl::get<20>(*this)); break; }
case 21: { visitor.visit(etl::get<21>(*this)); break; }
case 22: { visitor.visit(etl::get<22>(*this)); break; }
case 23: { visitor.visit(etl::get<23>(*this)); break; }
#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES)
case 24: { auto arg = etl::get<24>(*this); visitor.visit(arg); break; }
case 25: { auto arg = etl::get<25>(*this); visitor.visit(arg); break; }
case 26: { auto arg = etl::get<26>(*this); visitor.visit(arg); break; }
case 27: { auto arg = etl::get<27>(*this); visitor.visit(arg); break; }
case 28: { auto arg = etl::get<28>(*this); visitor.visit(arg); break; }
case 29: { auto arg = etl::get<29>(*this); visitor.visit(arg); break; }
case 30: { auto arg = etl::get<30>(*this); visitor.visit(arg); break; }
case 31: { auto arg = etl::get<31>(*this); visitor.visit(arg); break; }
case 24: { visitor.visit(etl::get<24>(*this)); break; }
case 25: { visitor.visit(etl::get<25>(*this)); break; }
case 26: { visitor.visit(etl::get<26>(*this)); break; }
case 27: { visitor.visit(etl::get<27>(*this)); break; }
case 28: { visitor.visit(etl::get<28>(*this)); break; }
case 29: { visitor.visit(etl::get<29>(*this)); break; }
case 30: { visitor.visit(etl::get<30>(*this)); break; }
case 31: { visitor.visit(etl::get<31>(*this)); break; }
#endif
#endif
#endif
@ -1119,7 +1123,10 @@ namespace etl
{
if (Index == index())
{
auto v = etl::get<Index>(*this);
// Workaround for MSVC (2023/05/13)
// It doesn't compile 'visitor.visit(etl::get<Index>(*this))' correctly for C++17 & C++20.
// Changed all of the instances for consistancy.
decltype(auto) v = etl::get<Index>(*this);
visitor.visit(v);
return true;
}
@ -1139,8 +1146,8 @@ namespace etl
{
// Workaround for MSVC (2023/05/13)
// It doesn't compile 'visitor.visit(etl::get<Index>(*this))' correctly for C++17 & C++20.
// Changed all of the instances for consistancy.
auto v = etl::get<Index>(*this);
// Changed all of the instances for consistancy.
decltype(auto) v = etl::get<Index>(*this);
visitor.visit(v);
return true;
}
@ -1306,7 +1313,7 @@ namespace etl
{
if (Index == index())
{
auto v = etl::get<Index>(*this);
decltype(auto) v = etl::get<Index>(*this);
visitor(v);
return true;
}
@ -1324,7 +1331,7 @@ namespace etl
{
if (Index == index())
{
auto v = etl::get<Index>(*this);
decltype(auto) v = etl::get<Index>(*this);
visitor(v);
return true;
}

View File

@ -32,6 +32,7 @@ SOFTWARE.
#define ETL_VISITOR_INCLUDED
#include "platform.h"
#include "type_traits.h"
//*****************************************************************************
///\defgroup visitor visitor
@ -149,6 +150,14 @@ namespace etl
#endif
//*****************************************************************
/// The tag to identify an etl::visitor.
///\ingroup visitor
//*****************************************************************
struct visitor_tag
{
};
#if ETL_USING_CPP11 && !defined(ETL_VISITOR_FORCE_CPP03_IMPLEMENTATION)
//*****************************************************************
@ -169,13 +178,13 @@ namespace etl
///\ingroup visitor
//*****************************************************************
template <typename T1>
class visitor<T1>
class visitor<T1> : public virtual visitor_tag
{
public:
virtual ~visitor() = default;
virtual void visit(T1&) = 0;
virtual void visit(T1) = 0;
};
#else
@ -189,28 +198,28 @@ namespace etl
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
class visitor
class visitor : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T7&) = 0;
virtual void visit(T8&) = 0;
virtual void visit(T9&) = 0;
virtual void visit(T10&) = 0;
virtual void visit(T11&) = 0;
virtual void visit(T12&) = 0;
virtual void visit(T13&) = 0;
virtual void visit(T14&) = 0;
virtual void visit(T15&) = 0;
virtual void visit(T16&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
virtual void visit(T7) = 0;
virtual void visit(T8) = 0;
virtual void visit(T9) = 0;
virtual void visit(T10) = 0;
virtual void visit(T11) = 0;
virtual void visit(T12) = 0;
virtual void visit(T13) = 0;
virtual void visit(T14) = 0;
virtual void visit(T15) = 0;
virtual void visit(T16) = 0;
};
//*****************************************************************
@ -222,27 +231,27 @@ namespace etl
typename T5, typename T6, typename T7, typename T8,
typename T9, typename T10, typename T11, typename T12,
typename T13, typename T14, typename T15>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T7&) = 0;
virtual void visit(T8&) = 0;
virtual void visit(T9&) = 0;
virtual void visit(T10&) = 0;
virtual void visit(T11&) = 0;
virtual void visit(T12&) = 0;
virtual void visit(T13&) = 0;
virtual void visit(T14&) = 0;
virtual void visit(T15&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
virtual void visit(T7) = 0;
virtual void visit(T8) = 0;
virtual void visit(T9) = 0;
virtual void visit(T10) = 0;
virtual void visit(T11) = 0;
virtual void visit(T12) = 0;
virtual void visit(T13) = 0;
virtual void visit(T14) = 0;
virtual void visit(T15) = 0;
};
//*****************************************************************
@ -254,26 +263,26 @@ namespace etl
typename T5, typename T6, typename T7, typename T8,
typename T9, typename T10, typename T11, typename T12,
typename T13, typename T14>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T7&) = 0;
virtual void visit(T8&) = 0;
virtual void visit(T9&) = 0;
virtual void visit(T10&) = 0;
virtual void visit(T11&) = 0;
virtual void visit(T12&) = 0;
virtual void visit(T13&) = 0;
virtual void visit(T14&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
virtual void visit(T7) = 0;
virtual void visit(T8) = 0;
virtual void visit(T9) = 0;
virtual void visit(T10) = 0;
virtual void visit(T11) = 0;
virtual void visit(T12) = 0;
virtual void visit(T13) = 0;
virtual void visit(T14) = 0;
};
//*****************************************************************
@ -285,25 +294,25 @@ namespace etl
typename T5, typename T6, typename T7, typename T8,
typename T9, typename T10, typename T11, typename T12,
typename T13>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T7&) = 0;
virtual void visit(T8&) = 0;
virtual void visit(T9&) = 0;
virtual void visit(T10&) = 0;
virtual void visit(T11&) = 0;
virtual void visit(T12&) = 0;
virtual void visit(T13&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
virtual void visit(T7) = 0;
virtual void visit(T8) = 0;
virtual void visit(T9) = 0;
virtual void visit(T10) = 0;
virtual void visit(T11) = 0;
virtual void visit(T12) = 0;
virtual void visit(T13) = 0;
};
//*****************************************************************
@ -314,24 +323,24 @@ namespace etl
template <typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8,
typename T9, typename T10, typename T11, typename T12>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T7&) = 0;
virtual void visit(T8&) = 0;
virtual void visit(T9&) = 0;
virtual void visit(T10&) = 0;
virtual void visit(T11&) = 0;
virtual void visit(T12&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
virtual void visit(T7) = 0;
virtual void visit(T8) = 0;
virtual void visit(T9) = 0;
virtual void visit(T10) = 0;
virtual void visit(T11) = 0;
virtual void visit(T12) = 0;
};
//*****************************************************************
@ -342,23 +351,23 @@ namespace etl
template <typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8,
typename T9, typename T10, typename T11>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T7&) = 0;
virtual void visit(T8&) = 0;
virtual void visit(T9&) = 0;
virtual void visit(T10&) = 0;
virtual void visit(T11&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
virtual void visit(T7) = 0;
virtual void visit(T8) = 0;
virtual void visit(T9) = 0;
virtual void visit(T10) = 0;
virtual void visit(T11) = 0;
};
//*****************************************************************
@ -369,22 +378,22 @@ namespace etl
template <typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8,
typename T9, typename T10>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T7&) = 0;
virtual void visit(T8&) = 0;
virtual void visit(T9&) = 0;
virtual void visit(T10&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
virtual void visit(T7) = 0;
virtual void visit(T8) = 0;
virtual void visit(T9) = 0;
virtual void visit(T10) = 0;
};
//*****************************************************************
@ -395,21 +404,21 @@ namespace etl
template <typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8,
typename T9>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8, T9> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T7&) = 0;
virtual void visit(T8&) = 0;
virtual void visit(T9&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
virtual void visit(T7) = 0;
virtual void visit(T8) = 0;
virtual void visit(T9) = 0;
};
//*****************************************************************
@ -419,20 +428,20 @@ namespace etl
//*****************************************************************
template <typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8>
class visitor<T1, T2, T3, T4, T5, T6, T7, T8> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T7&) = 0;
virtual void visit(T8&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
virtual void visit(T7) = 0;
virtual void visit(T8) = 0;
};
//*****************************************************************
@ -442,19 +451,19 @@ namespace etl
//*****************************************************************
template <typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7>
class visitor<T1, T2, T3, T4, T5, T6, T7>
class visitor<T1, T2, T3, T4, T5, T6, T7> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T7&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
virtual void visit(T7) = 0;
};
//*****************************************************************
@ -464,18 +473,18 @@ namespace etl
//*****************************************************************
template <typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6>
class visitor<T1, T2, T3, T4, T5, T6>
class visitor<T1, T2, T3, T4, T5, T6> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T6&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
virtual void visit(T6) = 0;
};
//*****************************************************************
@ -485,17 +494,17 @@ namespace etl
//*****************************************************************
template <typename T1, typename T2, typename T3, typename T4,
typename T5>
class visitor<T1, T2, T3, T4, T5>
class visitor<T1, T2, T3, T4, T5> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T5&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
virtual void visit(T5) = 0;
};
//*****************************************************************
@ -504,16 +513,16 @@ namespace etl
///\ingroup visitor
//*****************************************************************
template <typename T1, typename T2, typename T3, typename T4>
class visitor<T1, T2, T3, T4>
class visitor<T1, T2, T3, T4> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T4&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
virtual void visit(T4) = 0;
};
//*****************************************************************
@ -522,15 +531,15 @@ namespace etl
///\ingroup visitor
//*****************************************************************
template <typename T1, typename T2, typename T3>
class visitor<T1, T2, T3>
class visitor<T1, T2, T3> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T3&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
virtual void visit(T3) = 0;
};
//*****************************************************************
@ -539,14 +548,14 @@ namespace etl
///\ingroup visitor
//*****************************************************************
template <typename T1, typename T2>
class visitor<T1, T2>
class visitor<T1, T2> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T2&) = 0;
virtual void visit(T1) = 0;
virtual void visit(T2) = 0;
};
//*****************************************************************
@ -555,15 +564,33 @@ namespace etl
///\ingroup visitor
//*****************************************************************
template <typename T1>
class visitor<T1>
class visitor<T1> : public visitor_tag
{
public:
virtual ~visitor() {}
virtual void visit(T1&) = 0;
virtual void visit(T1) = 0;
};
#endif
//*****************************************************************
/// Is the type an etl::visitor?
///\ingroup visitor
//*****************************************************************
template <typename T>
struct is_visitor : public etl::bool_constant<etl::is_base_of<etl::visitor_tag, T>::value>
{
};
#if ETL_USING_CPP17
//*****************************************************************
/// Is the type an etl::visitor?
///\ingroup visitor
//*****************************************************************
template <typename T>
constexpr bool is_visitor_v = etl::is_visitor<T>::value;
#endif
}

View File

@ -810,7 +810,7 @@ namespace
//*************************************************************************
TEST(test_variant_accept_visitor)
{
struct Visitor : public etl::visitor<char, int, std::string>
struct Visitor : public etl::visitor<char&, int&, std::string&>
{
Visitor()
: result_c(0)
@ -822,16 +822,19 @@ namespace
void visit(char& c)
{
result_c = c;
++c;
}
void visit(int& i)
{
result_i = i;
++i;
}
void visit(std::string& s)
{
result_s = s;
s = "4";
}
char result_c;
@ -846,20 +849,23 @@ namespace
variant_etl = char(1);
variant_etl.accept(visitor);
CHECK_EQUAL(1, visitor.result_c);
CHECK_EQUAL(2, etl::get<char>(variant_etl));
variant_etl = int(2);
variant_etl.accept(visitor);
CHECK_EQUAL(2, visitor.result_i);
CHECK_EQUAL(3, etl::get<int>(variant_etl));
variant_etl = std::string("3");
variant_etl.accept(visitor);
CHECK_EQUAL("3", visitor.result_s);
CHECK_EQUAL("4", etl::get<std::string>(variant_etl));
}
//*************************************************************************
TEST(test_variant_accept_visitor_deprecated)
{
struct Visitor : public etl::visitor<char, int, std::string>
struct Visitor : public etl::visitor<char&, int&, std::string&>
{
Visitor()
: result_c(0)
@ -871,16 +877,19 @@ namespace
void visit(char& c)
{
result_c = c;
++c;
}
void visit(int& i)
{
result_i = i;
++i;
}
void visit(std::string& s)
{
result_s = s;
s = "4";
}
char result_c;
@ -895,21 +904,23 @@ namespace
variant_etl = char(1);
variant_etl.accept_visitor(visitor);
CHECK_EQUAL(1, visitor.result_c);
CHECK_EQUAL(2, etl::get<char>(variant_etl));
variant_etl = int(2);
variant_etl.accept_visitor(visitor);
CHECK_EQUAL(2, visitor.result_i);
CHECK_EQUAL(3, etl::get<int>(variant_etl));
variant_etl = std::string("3");
//variant_etl.accept_visitor(visitor);
variant_etl.accept(visitor);
variant_etl.accept_visitor(visitor);
CHECK_EQUAL("3", visitor.result_s);
CHECK_EQUAL("4", etl::get<std::string>(variant_etl));
}
//*************************************************************************
TEST(test_const_variant_accept_visitor)
{
struct Visitor : public etl::visitor<char, int, std::string>
struct Visitor : public etl::visitor<const char&, const int&, const std::string&>
{
Visitor()
: result_c(0)
@ -918,17 +929,17 @@ namespace
{
}
void visit(char& c)
void visit(const char& c)
{
result_c = c;
}
void visit(int& i)
void visit(const int& i)
{
result_i = i;
}
void visit(std::string& s)
void visit(const std::string& s)
{
result_s = s;
}
@ -961,7 +972,7 @@ namespace
//*************************************************************************
TEST(test_const_variant_accept_visitor_deprecated)
{
struct Visitor : public etl::visitor<char, int, std::string>
struct Visitor : public etl::visitor<char, int, const std::string&>
{
Visitor()
: result_c(0)
@ -970,17 +981,17 @@ namespace
{
}
void visit(char& c)
void visit(char c)
{
result_c = c;
}
void visit(int& i)
void visit(int i)
{
result_i = i;
}
void visit(std::string& s)
void visit(const std::string& s)
{
result_s = s;
}
@ -1024,19 +1035,22 @@ namespace
{
}
void operator()(char c)
void operator()(char& c)
{
result_c = c;
++c;
}
void operator()(int i)
void operator()(int& i)
{
result_i = i;
++i;
}
void operator()(const std::string& s)
void operator()(std::string& s)
{
result_s = s;
s = "4";
}
char result_c;
@ -1051,14 +1065,17 @@ namespace
variant_etl = char(1);
variant_etl.accept(visitor);
CHECK_EQUAL(1, visitor.result_c);
CHECK_EQUAL(2, etl::get<char>(variant_etl));
variant_etl = int(2);
variant_etl.accept(visitor);
CHECK_EQUAL(2, visitor.result_i);
CHECK_EQUAL(3, etl::get<int>(variant_etl));
variant_etl = std::string("3");
variant_etl.accept(visitor);
CHECK_EQUAL("3", visitor.result_s);
CHECK_EQUAL("4", etl::get<std::string>(variant_etl));
}
//*************************************************************************
@ -1150,7 +1167,7 @@ namespace
variant_etl = char(1);
const test_variant_etl_3 const_variant_etl1(variant_etl);
const_variant_etl1.accept(visitor);
CHECK_EQUAL(1, visitor.result_c);
CHECK_EQUAL(1, int(visitor.result_c));
variant_etl = int(2);
const test_variant_etl_3 const_variant_etl2(variant_etl);
@ -1206,13 +1223,11 @@ namespace
variant_etl = int(2);
const test_variant_etl_3 const_variant_etl2(variant_etl);
//const_variant_etl2.accept_functor(visitor);
const_variant_etl2.accept(visitor);
CHECK_EQUAL(2, visitor.result_i);
variant_etl = std::string("3");
const test_variant_etl_3 const_variant_etl3(variant_etl);
//const_variant_etl3.accept_functor(visitor);
const_variant_etl3.accept(visitor);
CHECK_EQUAL("3", visitor.result_s);
}
@ -1225,23 +1240,26 @@ namespace
int result_i;
std::string result_s;
auto visitor = etl::make_overload([&result_c](char) { result_c = 1; },
[&result_i](int) { result_i = 2; },
[&result_s](const std::string&) { result_s = "3"; });
auto visitor = etl::make_overload([&result_c](char& c) { result_c = 1; ++c; },
[&result_i](int& i) { result_i = 2; ++i; },
[&result_s](std::string& s) { result_s = "3"; s = "4"; });
test_variant_etl_3 variant_etl;
variant_etl = char(1);
variant_etl.accept(visitor);
CHECK_EQUAL(1, result_c);
CHECK_EQUAL(2, etl::get<char>(variant_etl));
variant_etl = int(2);
variant_etl.accept(visitor);
CHECK_EQUAL(2, result_i);
CHECK_EQUAL(3, etl::get<int>(variant_etl));
variant_etl = std::string("3");
variant_etl.accept(visitor);
CHECK_EQUAL("3", result_s);
CHECK_EQUAL("4", etl::get<std::string>(variant_etl));
}
//*************************************************************************
@ -1262,12 +1280,10 @@ namespace
CHECK_EQUAL(1, result_c);
variant_etl = int(2);
//variant_etl.accept_functor(visitor);
variant_etl.accept(visitor);
CHECK_EQUAL(2, result_i);
variant_etl = std::string("3");
//variant_etl.accept_functor(visitor);
variant_etl.accept(visitor);
CHECK_EQUAL("3", result_s);
}
@ -1321,13 +1337,11 @@ namespace
variant_etl = int(2);
const test_variant_etl_3 const_variant_etl2(variant_etl);
//const_variant_etl2.accept_functor(visitor);
const_variant_etl2.accept(visitor);
CHECK_EQUAL(2, result_i);
variant_etl = std::string("3");
const test_variant_etl_3 const_variant_etl3(variant_etl);
//const_variant_etl3.accept_functor(visitor);
const_variant_etl3.accept(visitor);
CHECK_EQUAL("3", result_s);
}

View File

@ -43,14 +43,14 @@ class Triangle;
// Circle will be passed by reference.
// Triangle will be passed by const reference.
//*****************************************************************************
typedef etl::visitor<Square, Circle, const Triangle> DrawVisitorType;
typedef etl::visitor<Square&, Circle&, const Triangle&> DrawVisitorType;
//*****************************************************************************
// What classes do you want the visitors to handle?
// Square will be passed by reference.
// Triangle will be passed by const reference.
//*****************************************************************************
typedef etl::visitor<Square, const Triangle> LogVisitorType;
typedef etl::visitor<Square&, const Triangle&> LogVisitorType;
//*****************************************************************************
// Base shape.
@ -369,7 +369,7 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -383,8 +383,8 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -398,9 +398,9 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -414,10 +414,10 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -432,11 +432,11 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -451,12 +451,12 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -471,13 +471,13 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<7, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
void visit(Shape<7, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -492,14 +492,14 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<7, ShapeVisitor>&) {}
void visit(Shape<8, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
void visit(Shape<7, ShapeVisitor>) {}
void visit(Shape<8, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -515,15 +515,15 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<7, ShapeVisitor>&) {}
void visit(Shape<8, ShapeVisitor>&) {}
void visit(Shape<9, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
void visit(Shape<7, ShapeVisitor>) {}
void visit(Shape<8, ShapeVisitor>) {}
void visit(Shape<9, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -539,16 +539,16 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<7, ShapeVisitor>&) {}
void visit(Shape<8, ShapeVisitor>&) {}
void visit(Shape<9, ShapeVisitor>&) {}
void visit(Shape<10, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
void visit(Shape<7, ShapeVisitor>) {}
void visit(Shape<8, ShapeVisitor>) {}
void visit(Shape<9, ShapeVisitor>) {}
void visit(Shape<10, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -565,17 +565,17 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<7, ShapeVisitor>&) {}
void visit(Shape<8, ShapeVisitor>&) {}
void visit(Shape<9, ShapeVisitor>&) {}
void visit(Shape<10, ShapeVisitor>&) {}
void visit(Shape<11, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
void visit(Shape<7, ShapeVisitor>) {}
void visit(Shape<8, ShapeVisitor>) {}
void visit(Shape<9, ShapeVisitor>) {}
void visit(Shape<10, ShapeVisitor>) {}
void visit(Shape<11, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -591,18 +591,18 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<7, ShapeVisitor>&) {}
void visit(Shape<8, ShapeVisitor>&) {}
void visit(Shape<9, ShapeVisitor>&) {}
void visit(Shape<10, ShapeVisitor>&) {}
void visit(Shape<11, ShapeVisitor>&) {}
void visit(Shape<12, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
void visit(Shape<7, ShapeVisitor>) {}
void visit(Shape<8, ShapeVisitor>) {}
void visit(Shape<9, ShapeVisitor>) {}
void visit(Shape<10, ShapeVisitor>) {}
void visit(Shape<11, ShapeVisitor>) {}
void visit(Shape<12, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -619,19 +619,19 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<7, ShapeVisitor>&) {}
void visit(Shape<8, ShapeVisitor>&) {}
void visit(Shape<9, ShapeVisitor>&) {}
void visit(Shape<10, ShapeVisitor>&) {}
void visit(Shape<11, ShapeVisitor>&) {}
void visit(Shape<12, ShapeVisitor>&) {}
void visit(Shape<13, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
void visit(Shape<7, ShapeVisitor>) {}
void visit(Shape<8, ShapeVisitor>) {}
void visit(Shape<9, ShapeVisitor>) {}
void visit(Shape<10, ShapeVisitor>) {}
void visit(Shape<11, ShapeVisitor>) {}
void visit(Shape<12, ShapeVisitor>) {}
void visit(Shape<13, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -648,20 +648,20 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<7, ShapeVisitor>&) {}
void visit(Shape<8, ShapeVisitor>&) {}
void visit(Shape<9, ShapeVisitor>&) {}
void visit(Shape<10, ShapeVisitor>&) {}
void visit(Shape<11, ShapeVisitor>&) {}
void visit(Shape<12, ShapeVisitor>&) {}
void visit(Shape<13, ShapeVisitor>&) {}
void visit(Shape<14, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
void visit(Shape<7, ShapeVisitor>) {}
void visit(Shape<8, ShapeVisitor>) {}
void visit(Shape<9, ShapeVisitor>) {}
void visit(Shape<10, ShapeVisitor>) {}
void visit(Shape<11, ShapeVisitor>) {}
void visit(Shape<12, ShapeVisitor>) {}
void visit(Shape<13, ShapeVisitor>) {}
void visit(Shape<14, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -678,21 +678,21 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<7, ShapeVisitor>&) {}
void visit(Shape<8, ShapeVisitor>&) {}
void visit(Shape<9, ShapeVisitor>&) {}
void visit(Shape<10, ShapeVisitor>&) {}
void visit(Shape<11, ShapeVisitor>&) {}
void visit(Shape<12, ShapeVisitor>&) {}
void visit(Shape<13, ShapeVisitor>&) {}
void visit(Shape<14, ShapeVisitor>&) {}
void visit(Shape<15, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
void visit(Shape<7, ShapeVisitor>) {}
void visit(Shape<8, ShapeVisitor>) {}
void visit(Shape<9, ShapeVisitor>) {}
void visit(Shape<10, ShapeVisitor>) {}
void visit(Shape<11, ShapeVisitor>) {}
void visit(Shape<12, ShapeVisitor>) {}
void visit(Shape<13, ShapeVisitor>) {}
void visit(Shape<14, ShapeVisitor>) {}
void visit(Shape<15, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
@ -709,27 +709,43 @@ namespace
{
public:
void visit(Shape<1, ShapeVisitor>&) {}
void visit(Shape<2, ShapeVisitor>&) {}
void visit(Shape<3, ShapeVisitor>&) {}
void visit(Shape<4, ShapeVisitor>&) {}
void visit(Shape<5, ShapeVisitor>&) {}
void visit(Shape<6, ShapeVisitor>&) {}
void visit(Shape<7, ShapeVisitor>&) {}
void visit(Shape<8, ShapeVisitor>&) {}
void visit(Shape<9, ShapeVisitor>&) {}
void visit(Shape<10, ShapeVisitor>&) {}
void visit(Shape<11, ShapeVisitor>&) {}
void visit(Shape<12, ShapeVisitor>&) {}
void visit(Shape<13, ShapeVisitor>&) {}
void visit(Shape<14, ShapeVisitor>&) {}
void visit(Shape<15, ShapeVisitor>&) {}
void visit(Shape<16, ShapeVisitor>&) {}
void visit(Shape<1, ShapeVisitor>) {}
void visit(Shape<2, ShapeVisitor>) {}
void visit(Shape<3, ShapeVisitor>) {}
void visit(Shape<4, ShapeVisitor>) {}
void visit(Shape<5, ShapeVisitor>) {}
void visit(Shape<6, ShapeVisitor>) {}
void visit(Shape<7, ShapeVisitor>) {}
void visit(Shape<8, ShapeVisitor>) {}
void visit(Shape<9, ShapeVisitor>) {}
void visit(Shape<10, ShapeVisitor>) {}
void visit(Shape<11, ShapeVisitor>) {}
void visit(Shape<12, ShapeVisitor>) {}
void visit(Shape<13, ShapeVisitor>) {}
void visit(Shape<14, ShapeVisitor>) {}
void visit(Shape<15, ShapeVisitor>) {}
void visit(Shape<16, ShapeVisitor>) {}
};
// This test just needs to compile without errors.
CHECK(true);
}
//*************************************************************************
struct NotVisitor {};
TEST(test_is_visitor)
{
#if ETL_USING_CPP17
CHECK_TRUE(etl::is_visitor_v<DrawVisitor>);
CHECK_TRUE(etl::is_visitor_v<LogVisitor>);
CHECK_FALSE(etl::is_visitor_v<NotVisitor>);
#else
CHECK_TRUE(etl::is_visitor<DrawVisitor>::value);
CHECK_TRUE(etl::is_visitor<LogVisitor>::value);
CHECK_FALSE(etl::is_visitor<NotVisitor>::value);
#endif
}
}
}