FIT_TEST_CASE() { FIT_TEST_CHECK(max_f()(3, 4) == std::max(3, 4)); FIT_TEST_CHECK(sum_f()(1, 2) == 3); FIT_STATIC_TEST_CHECK(sum_f()(1, 2) == 3); }
FIT_TEST_CASE() { FIT_TEST_CHECK(sum_f()(1, 2) == 3); FIT_TEST_CHECK(sum_f()(1.0, 2.0) == 0); FIT_TEST_CHECK(sum_f()("", "") == 0); FIT_STATIC_TEST_CHECK(sum_f()(1, 2) == 3); FIT_STATIC_TEST_CHECK(sum_f()("", "") == 0); }
namespace test_static { struct sum_f { template<class T, class U> constexpr T operator()(T x, U y) const { return x+y; } }; struct add_one_f { template<class T> constexpr T operator()(T x) const { return x+1; } }; BOOST_HOF_STATIC_FUNCTION(sum_partial) = boost::hof::partial(sum_f()); BOOST_HOF_TEST_CASE() { #ifndef _MSC_VER STATIC_ASSERT_EMPTY(sum_partial); #endif BOOST_HOF_TEST_CHECK(3 == sum_partial(1, 2)); BOOST_HOF_TEST_CHECK(3 == sum_partial(1)(2)); } BOOST_HOF_STATIC_FUNCTION(add_one_pipable) = boost::hof::pipable(add_one_f()); BOOST_HOF_TEST_CASE() { // TODO: Make this work on msvc #ifndef _MSC_VER STATIC_ASSERT_EMPTY(add_one_pipable); #endif BOOST_HOF_TEST_CHECK(3 == add_one_pipable(2)); BOOST_HOF_TEST_CHECK(3 == (2 | add_one_pipable)); } BOOST_HOF_STATIC_FUNCTION(sum_infix) = boost::hof::infix(sum_f()); BOOST_HOF_TEST_CASE() { // TODO: Make this work on msvc #ifndef _MSC_VER STATIC_ASSERT_EMPTY(sum_infix); #endif BOOST_HOF_TEST_CHECK(3 == (1 <sum_infix> 2)); } }
int main() { mult_f(0, 0);//вызов функции int result_sum_f= sum_f(5,4); printf("\nresult in decimal: %d result in hex: %x\n", result_sum_f, result_sum_f); return 0; }
namespace test_constexpr { struct sum_f { template<class T, class U> constexpr T operator()(T x, U y) const { return x+y; } }; BOOST_HOF_STATIC_FUNCTION(sum_init) = sum_f(); BOOST_HOF_TEST_CASE() { // TODO: Should be empty on MSVC as well #ifndef _MSC_VER STATIC_ASSERT_EMPTY(sum_init); #endif BOOST_HOF_TEST_CHECK(3 == sum_init(1, 2)); BOOST_HOF_STATIC_TEST_CHECK(3 == sum_init(1, 2)); } BOOST_HOF_STATIC_FUNCTION(sum_partial) = boost::hof::partial(sum_f()); BOOST_HOF_TEST_CASE() { #ifndef _MSC_VER STATIC_ASSERT_EMPTY(sum_partial); #endif BOOST_HOF_TEST_CHECK(3 == sum_partial(1, 2)); BOOST_HOF_TEST_CHECK(3 == sum_partial(1)(2)); BOOST_HOF_STATIC_TEST_CHECK(3 == sum_partial(1, 2)); BOOST_HOF_STATIC_TEST_CHECK(3 == sum_partial(1)(2)); } }
FIT_TEST_CASE() { FIT_TEST_CHECK(fit::compress(sum_f(), std::string())("hello", "-", "world") == "hello-world"); }
int main() { #if 1 // printf(%i or %f) only work on release build int a = -5; int b = 3; int c = 0; // long l = 0; if (c > (b - 10)) { c = c + 10; } else if (c > (b - 8)) { c = c + 8; } else { c = c - 1; } // asm ("addiu t0, $0, 10"); // c = sum_i(a, b); // c = sum_all<int>(a, b, 5, 6, 7, 8, 9, 1, 2, 3); // l = sum_l(a, b); // c = sum_all<long>(a, b, 5, 6, 7, 8, 9, 1, 2, 3); /* gi += b; c = c + gi + ga[3]; c= delayslot_fill_test(); c= ReplaceUsesWithZeroReg_test(); c += (int)l;*/ // printstr("Hello world\n"); return c; #endif #if 0 // float is work float f1, f2, f3 = 0; f2 = 5.01 + 7.03; f1 = sum_f(f2, f3); // f1 = sum_all<float>((float)a, (float)b, 5.3, 6, 7, 8, 9, 1, 2, 3); // not allow in var_arg() // printf("f1 = %f\n", f1); return f2; #endif #if 0 double f1, f2, f3 = 0; f2 = 7.2; f3 = 6.3; f1 = 2.3 + 4.6 + f2 + f3; // printf("f1 = %f\n", f1); return f1; #endif #if 0 // double arguments not work in my current llvm working double f1, f2, f3 = 0; // f1 = sum_d(f2, f3); f1 = sum_all<double>(4.2, 5.3, 6, 7, 8, 9, 1, 2, 3); // printf("f1 = %f\n", (float)f1); return f1; #endif }