diff --git a/include/etl/overload.h b/include/etl/overload.h index 5b636c942..6f22b4c7b 100644 --- a/include/etl/overload.h +++ b/include/etl/overload.h @@ -35,10 +35,9 @@ SOFTWARE. #include "utility.h" #include "type_traits.h" -#if ETL_USING_CPP17 - namespace etl { +#if ETL_USING_CPP17 //************************************************************************* /// Variadic template definition of overload for C++17 and above. //************************************************************************* @@ -61,8 +60,39 @@ namespace etl { return overload{ etl::forward(overloads)... }; } -} +#elif ETL_USING_CPP11 + //************************************************************************* + /// Variadic template definition of overload for C++11 & C++14. + //************************************************************************* + template + struct overload; + + //************************************************************************* + template + struct overload : TOverload, overload + { + overload(TOverload ovl0, TRest... rest) : TOverload(ovl0), overload(rest...) {} + + using TOverload::operator(); + using overload::operator(); + }; + + //************************************************************************* + template + struct overload : TOverload + { + overload(TOverload ovl0) : TOverload(ovl0) {} + + using TOverload::operator(); + }; + //************************************************************************* + template + overload make_overload(TRest... overloads) + { + return overload(overloads...); + } #endif +} #endif diff --git a/test/test_overload.cpp b/test/test_overload.cpp index baef8b9fd..68da87dbe 100644 --- a/test/test_overload.cpp +++ b/test/test_overload.cpp @@ -30,7 +30,7 @@ SOFTWARE. #include "etl/overload.h" -#if ETL_USING_CPP17 +#if ETL_USING_CPP11 #include @@ -100,6 +100,7 @@ namespace CHECK(result.bs == true); } +#if ETL_USING_CPP_17 //************************************************************************* TEST(test_overload_lambdas_initializer_list) { @@ -136,6 +137,7 @@ namespace CHECK(result.bd == false); CHECK(result.bs == true); } +#endif //************************************************************************* TEST(test_visitor_overload)