mirror of
https://github.com/boostorg/hof.git
synced 2026-01-20 16:42:14 +00:00
96 lines
1.8 KiB
C++
96 lines
1.8 KiB
C++
#include "test.hpp"
|
|
#include <fit/reveal.hpp>
|
|
#include <fit/conditional.hpp>
|
|
#include <fit/static.hpp>
|
|
#include <fit/lambda.hpp>
|
|
#include <fit/fix.hpp>
|
|
|
|
namespace reveal_test {
|
|
|
|
#define CONDITIONAL_FUNCTION(n) \
|
|
struct t ## n {}; \
|
|
struct f ## n \
|
|
{ \
|
|
constexpr int operator()(t ## n) const \
|
|
{ \
|
|
return n; \
|
|
} \
|
|
};
|
|
|
|
CONDITIONAL_FUNCTION(1)
|
|
CONDITIONAL_FUNCTION(2)
|
|
CONDITIONAL_FUNCTION(3)
|
|
|
|
static constexpr fit::static_<fit::conditional_adaptor<f1, f2, f3> > f = {};
|
|
|
|
FIT_TEST_CASE()
|
|
{
|
|
FIT_TEST_CHECK(fit::reveal(f)(t1()) == 1);
|
|
FIT_TEST_CHECK(fit::reveal(f)(t2()) == 2);
|
|
FIT_TEST_CHECK(fit::reveal(f)(t3()) == 3);
|
|
// fit::reveal(f)(1);
|
|
}
|
|
#if FIT_HAS_STATIC_LAMBDA
|
|
#ifndef _MSC_VER
|
|
static constexpr auto lam = fit::conditional(
|
|
FIT_STATIC_LAMBDA(t1)
|
|
{
|
|
return 1;
|
|
},
|
|
FIT_STATIC_LAMBDA(t2)
|
|
{
|
|
return 2;
|
|
},
|
|
FIT_STATIC_LAMBDA(t3)
|
|
{
|
|
return 3;
|
|
}
|
|
);
|
|
|
|
FIT_TEST_CASE()
|
|
{
|
|
STATIC_ASSERT_EMPTY(lam);
|
|
STATIC_ASSERT_EMPTY(fit::reveal(lam));
|
|
FIT_TEST_CHECK(fit::reveal(lam)(t1()) == 1);
|
|
FIT_TEST_CHECK(fit::reveal(lam)(t2()) == 2);
|
|
FIT_TEST_CHECK(fit::reveal(lam)(t3()) == 3);
|
|
|
|
// fit::reveal(lam)(1);
|
|
}
|
|
#endif
|
|
|
|
FIT_STATIC_LAMBDA_FUNCTION(static_fun) = fit::conditional(
|
|
[](t1)
|
|
{
|
|
return 1;
|
|
},
|
|
[](t2)
|
|
{
|
|
return 2;
|
|
},
|
|
[](t3)
|
|
{
|
|
return 3;
|
|
}
|
|
);
|
|
|
|
FIT_TEST_CASE()
|
|
{
|
|
#ifndef _MSC_VER
|
|
STATIC_ASSERT_EMPTY(static_fun);
|
|
// STATIC_ASSERT_EMPTY(fit::reveal(static_fun));
|
|
#endif
|
|
FIT_TEST_CHECK(fit::reveal(static_fun)(t1()) == 1);
|
|
FIT_TEST_CHECK(fit::reveal(static_fun)(t2()) == 2);
|
|
FIT_TEST_CHECK(fit::reveal(static_fun)(t3()) == 3);
|
|
|
|
FIT_TEST_CHECK(static_fun(t1()) == 1);
|
|
FIT_TEST_CHECK(static_fun(t2()) == 2);
|
|
FIT_TEST_CHECK(static_fun(t3()) == 3);
|
|
|
|
// fit::reveal(static_fun)(1);
|
|
}
|
|
#endif
|
|
|
|
}
|