summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hof/test/static_def
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/hof/test/static_def')
-rw-r--r--src/boost/libs/hof/test/static_def/static_def.cpp59
-rw-r--r--src/boost/libs/hof/test/static_def/static_def.hpp61
-rw-r--r--src/boost/libs/hof/test/static_def/static_def2.cpp58
3 files changed, 178 insertions, 0 deletions
diff --git a/src/boost/libs/hof/test/static_def/static_def.cpp b/src/boost/libs/hof/test/static_def/static_def.cpp
new file mode 100644
index 00000000..83e9c797
--- /dev/null
+++ b/src/boost/libs/hof/test/static_def/static_def.cpp
@@ -0,0 +1,59 @@
+/*=============================================================================
+ Copyright (c) 2017 Paul Fultz II
+ static_def.cpp
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+
+#include <cstdio>
+#include "static_def.hpp"
+
+extern int f();
+
+extern void* f_sum_lambda_addr();
+extern void* f_sum_fo_addr();
+
+extern void* sum_lambda_addr();
+extern void* sum_fo_addr();
+
+extern void* f_sum_var_addr();
+extern void* f_sum_constexpr_fo_addr();
+
+extern void* sum_var_addr();
+extern void* sum_constexpr_fo_addr();
+
+void* sum_lambda_addr()
+{
+ return (void*)&fit_test::fit_sum_lambda;
+}
+void* sum_fo_addr()
+{
+ return (void*)&fit_test::fit_sum_fo;
+}
+
+void* sum_var_addr()
+{
+ return (void*)&fit_test::fit_sum_var;
+}
+void* sum_constexpr_fo_addr()
+{
+ return (void*)&fit_test::fit_sum_constexpr_fo;
+}
+
+int main()
+{
+ if (fit_test::fit_sum_fo(1, 2) != 3) printf("FAILED\n");
+ if (fit_test::fit_sum_lambda(1, 2) != 3) printf("FAILED\n");
+ if (fit_test::fit_sum(1, 2) != 3) printf("FAILED\n");
+
+#if BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR
+ if (sum_lambda_addr() != f_sum_lambda_addr()) printf("FAILED: Lambda\n");
+ if (sum_fo_addr() != f_sum_fo_addr()) printf("FAILED: Function object\n");
+#endif
+
+#if BOOST_HOF_HAS_UNIQUE_STATIC_VAR
+ if (sum_var_addr() != f_sum_var_addr()) printf("FAILED: Lambda\n");
+ if (sum_constexpr_fo_addr() != f_sum_constexpr_fo_addr()) printf("FAILED: Function object\n");
+#endif
+ return f();
+}
diff --git a/src/boost/libs/hof/test/static_def/static_def.hpp b/src/boost/libs/hof/test/static_def/static_def.hpp
new file mode 100644
index 00000000..10574c64
--- /dev/null
+++ b/src/boost/libs/hof/test/static_def/static_def.hpp
@@ -0,0 +1,61 @@
+/*=============================================================================
+ Copyright (c) 2017 Paul Fultz II
+ static_def.hpp
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+
+#ifndef GUARD_STATIC_DEF
+#define GUARD_STATIC_DEF
+
+#include <boost/hof/function.hpp>
+#include <boost/hof/lambda.hpp>
+
+// MSVC seems to not support unique addressing at all
+#if defined (_MSC_VER)
+#define BOOST_HOF_HAS_UNIQUE_STATIC_VAR 0
+#define BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR 0
+// Gcc 4.6 only supports unique addressing for non-lambdas
+#elif defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7
+#define BOOST_HOF_HAS_UNIQUE_STATIC_VAR 1
+#define BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR 0
+#else
+#define BOOST_HOF_HAS_UNIQUE_STATIC_VAR 1
+#define BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR 1
+#endif
+
+namespace fit_test {
+
+BOOST_HOF_STATIC_LAMBDA_FUNCTION(fit_sum_lambda) = [](int x, int y)
+{
+ return x + y;
+};
+
+struct fit_sum_f
+{
+ constexpr int operator()(int x, int y) const
+ {
+ return x + y;
+ }
+};
+
+BOOST_HOF_STATIC_LAMBDA_FUNCTION(fit_sum_fo) = fit_sum_f();
+
+BOOST_HOF_STATIC_FUNCTION(fit_sum_constexpr_fo) = fit_sum_f();
+
+BOOST_HOF_DECLARE_STATIC_VAR(fit_sum_var, fit_sum_f);
+
+// BOOST_HOF_STATIC_FUNCTION(fit_sum) = [](auto x, auto y)
+// {
+// return x + y;
+// };
+
+template<class T>
+T fit_sum(T x, T y)
+{
+ return x + y;
+};
+
+}
+
+#endif
diff --git a/src/boost/libs/hof/test/static_def/static_def2.cpp b/src/boost/libs/hof/test/static_def/static_def2.cpp
new file mode 100644
index 00000000..b5e86e56
--- /dev/null
+++ b/src/boost/libs/hof/test/static_def/static_def2.cpp
@@ -0,0 +1,58 @@
+/*=============================================================================
+ Copyright (c) 2017 Paul Fultz II
+ static_def2.cpp
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+
+#include <cstdio>
+#include "static_def.hpp"
+
+extern void* f_sum_lambda_addr();
+extern void* f_sum_fo_addr();
+
+extern void* sum_lambda_addr();
+extern void* sum_fo_addr();
+
+extern void* f_sum_var_addr();
+extern void* f_sum_constexpr_fo_addr();
+
+extern void* sum_var_addr();
+extern void* sum_constexpr_fo_addr();
+
+void* f_sum_lambda_addr()
+{
+ return (void*)&fit_test::fit_sum_lambda;
+}
+void* f_sum_fo_addr()
+{
+ return (void*)&fit_test::fit_sum_fo;
+}
+
+void* f_sum_var_addr()
+{
+ return (void*)&fit_test::fit_sum_var;
+}
+void* f_sum_constexpr_fo_addr()
+{
+ return (void*)&fit_test::fit_sum_constexpr_fo;
+}
+
+int f()
+{
+ if (fit_test::fit_sum_fo(1, 2) != 3) printf("FAILED\n");
+ if (fit_test::fit_sum_lambda(1, 2) != 3) printf("FAILED\n");
+ if (fit_test::fit_sum(1, 2) != 3) printf("FAILED\n");
+
+#if BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR
+ if (sum_lambda_addr() != f_sum_lambda_addr()) printf("FAILED: Lambda\n");
+ if (sum_fo_addr() != f_sum_fo_addr()) printf("FAILED: Function object\n");
+#endif
+
+#if BOOST_HOF_HAS_UNIQUE_STATIC_VAR
+ if (sum_var_addr() != f_sum_var_addr()) printf("FAILED: Lambda\n");
+ if (sum_constexpr_fo_addr() != f_sum_constexpr_fo_addr()) printf("FAILED: Function object\n");
+#endif
+ return 0;
+}
+