mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
etl::overload in C++17 only
This commit is contained in:
parent
b7a1b65276
commit
e21426112e
@ -37,7 +37,7 @@ SOFTWARE.
|
||||
|
||||
namespace etl
|
||||
{
|
||||
#if ETL_USING_CPP17 && !defined(ETL_OVERLOAD_FORCE_CPP14)
|
||||
#if ETL_USING_CPP17
|
||||
|
||||
//*************************************************************************
|
||||
/// Variadic template definition of overload for C++17 and above.
|
||||
@ -53,10 +53,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
template<typename... TOverloads> overload(TOverloads...)->overload<TOverloads...>;
|
||||
|
||||
#else
|
||||
|
||||
//*************************************************************************
|
||||
/// Variadic template definition of overload for C++14.
|
||||
/// Variadic template definition of overload for C++11.
|
||||
//*************************************************************************
|
||||
template <typename TFirst, typename... TOthers>
|
||||
struct overload : TFirst, overload<TOthers...>
|
||||
@ -71,9 +69,6 @@ namespace etl
|
||||
using TFirst::operator();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
//*************************************************************************
|
||||
/// Make an overload.
|
||||
//*************************************************************************
|
||||
@ -82,7 +77,8 @@ namespace etl
|
||||
{
|
||||
return overload<TOverloads...>{ etl::forward<TOverloads>(overloads)... };
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -30,6 +30,8 @@ SOFTWARE.
|
||||
|
||||
#include "etl/overload.h"
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
@ -72,9 +74,8 @@ namespace
|
||||
|
||||
SUITE(test_overload)
|
||||
{
|
||||
#if ETL_USING_CPP17
|
||||
//*************************************************************************
|
||||
TEST(test_overload_lambdas)
|
||||
TEST(test_overload_lambdas_make_overload)
|
||||
{
|
||||
auto overload = etl::make_overload([](int i) { result.bi = true; },
|
||||
[](double d) { result.bd = true; },
|
||||
@ -98,12 +99,10 @@ namespace
|
||||
CHECK(result.bd == false);
|
||||
CHECK(result.bs == true);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_overload_lambdas_cpp17)
|
||||
TEST(test_overload_lambdas_initializer_list)
|
||||
{
|
||||
#if ETL_USING_CPP17 && !defined(ETL_OVERLOAD_FORCE_CPP14)
|
||||
result.clear();
|
||||
Function(int(1), etl::overload
|
||||
{
|
||||
@ -136,10 +135,8 @@ namespace
|
||||
CHECK(result.bi == false);
|
||||
CHECK(result.bd == false);
|
||||
CHECK(result.bs == true);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
//*************************************************************************
|
||||
TEST(test_visitor_overload)
|
||||
{
|
||||
@ -163,6 +160,7 @@ namespace
|
||||
CHECK(result.bd == false);
|
||||
CHECK(result.bs == true);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user