Skip to content

Commit

Permalink
Adds C++14 SFINAE Test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j-h committed Nov 14, 2016
1 parent 2275a61 commit 4d462f2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/lambda_overload_test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include <iostream>
#include <vector>

#include <mapbox/variant.hpp>
#include <mapbox/variant_visitor.hpp>

#if __cplusplus >= 201402L
#define HAS_CPP14_SUPPORT
#endif

using namespace mapbox::util;

template <typename Left, typename Right>
Expand Down Expand Up @@ -50,9 +55,38 @@ void test_singleton_variant()
apply_visitor(make_visitor([](int) {}), singleton);
}

#ifdef HAS_CPP14_SUPPORT
void test_lambda_overloads_sfinae()
{
variant<int, float, std::vector<int>> var;

auto visitor = make_visitor([](auto range) -> decltype(std::begin(range), void()) {
for (auto each : range)
std::cout << each << ' '; },
[](auto x) -> decltype(std::cout << x, void()) {
std::cout << x << std::endl;
});

var = 1;
apply_visitor(visitor, var);

var = 2.f;
apply_visitor(visitor, var);

var = std::vector<int>{4, 5, 6};
apply_visitor(visitor, var);
}
#endif

int main()
{
test_lambda_overloads();
test_singleton_variant();
test_lambda_overloads_capture();

#ifdef HAS_CPP14_SUPPORT
test_lambda_overloads_sfinae();
#endif
}

#undef HAS_CPP14_SUPPORT

0 comments on commit 4d462f2

Please sign in to comment.