static_def.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*=============================================================================
  2. Copyright (c) 2017 Paul Fultz II
  3. static_def.hpp
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #ifndef GUARD_STATIC_DEF
  8. #define GUARD_STATIC_DEF
  9. #include <boost/hof/function.hpp>
  10. #include <boost/hof/lambda.hpp>
  11. // MSVC seems to not support unique addressing at all
  12. #if defined (_MSC_VER)
  13. #define BOOST_HOF_HAS_UNIQUE_STATIC_VAR 0
  14. #define BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR 0
  15. // Gcc 4.6 only supports unique addressing for non-lambdas
  16. #elif defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7
  17. #define BOOST_HOF_HAS_UNIQUE_STATIC_VAR 1
  18. #define BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR 0
  19. #else
  20. #define BOOST_HOF_HAS_UNIQUE_STATIC_VAR 1
  21. #define BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR 1
  22. #endif
  23. namespace fit_test {
  24. BOOST_HOF_STATIC_LAMBDA_FUNCTION(fit_sum_lambda) = [](int x, int y)
  25. {
  26. return x + y;
  27. };
  28. struct fit_sum_f
  29. {
  30. constexpr int operator()(int x, int y) const
  31. {
  32. return x + y;
  33. }
  34. };
  35. BOOST_HOF_STATIC_LAMBDA_FUNCTION(fit_sum_fo) = fit_sum_f();
  36. BOOST_HOF_STATIC_FUNCTION(fit_sum_constexpr_fo) = fit_sum_f();
  37. BOOST_HOF_DECLARE_STATIC_VAR(fit_sum_var, fit_sum_f);
  38. // BOOST_HOF_STATIC_FUNCTION(fit_sum) = [](auto x, auto y)
  39. // {
  40. // return x + y;
  41. // };
  42. template<class T>
  43. T fit_sum(T x, T y)
  44. {
  45. return x + y;
  46. };
  47. }
  48. #endif