Skip to content

Commit

Permalink
Enabled etl::overload for C++11 & C++14
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wellbelove committed Sep 20, 2023
1 parent 26cf2af commit 8e83a26
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
36 changes: 33 additions & 3 deletions include/etl/overload.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//*************************************************************************
Expand All @@ -61,8 +60,39 @@ namespace etl
{
return overload<TOverloads...>{ etl::forward<TOverloads>(overloads)... };
}
}
#elif ETL_USING_CPP11
//*************************************************************************
/// Variadic template definition of overload for C++11 & C++14.
//*************************************************************************
template <typename... TRest>
struct overload;

//*************************************************************************
template <typename TOverload, typename... TRest>
struct overload<TOverload, TRest...> : TOverload, overload<TRest...>
{
overload(TOverload ovl0, TRest... rest) : TOverload(ovl0), overload<TRest...>(rest...) {}

using TOverload::operator();
using overload<TRest...>::operator();
};

//*************************************************************************
template <typename TOverload>
struct overload<TOverload> : TOverload
{
overload(TOverload ovl0) : TOverload(ovl0) {}

using TOverload::operator();
};

//*************************************************************************
template <typename... TRest>
overload<TRest...> make_overload(TRest... overloads)
{
return overload<TRest...>(overloads...);
}
#endif
}

#endif
4 changes: 3 additions & 1 deletion test/test_overload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SOFTWARE.

#include "etl/overload.h"

#if ETL_USING_CPP17
#if ETL_USING_CPP11

#include <iostream>

Expand Down Expand Up @@ -100,6 +100,7 @@ namespace
CHECK(result.bs == true);
}

#if ETL_USING_CPP_17
//*************************************************************************
TEST(test_overload_lambdas_initializer_list)
{
Expand Down Expand Up @@ -136,6 +137,7 @@ namespace
CHECK(result.bd == false);
CHECK(result.bs == true);
}
#endif

//*************************************************************************
TEST(test_visitor_overload)
Expand Down

0 comments on commit 8e83a26

Please sign in to comment.