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 8 #ifndef GUARD_STATIC_DEF 9 #define GUARD_STATIC_DEF 10 11 #include <boost/hof/function.hpp> 12 #include <boost/hof/lambda.hpp> 13 14 // MSVC seems to not support unique addressing at all 15 #if defined (_MSC_VER) 16 #define BOOST_HOF_HAS_UNIQUE_STATIC_VAR 0 17 #define BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR 0 18 // Gcc 4.6 only supports unique addressing for non-lambdas 19 #elif defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7 20 #define BOOST_HOF_HAS_UNIQUE_STATIC_VAR 1 21 #define BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR 0 22 #else 23 #define BOOST_HOF_HAS_UNIQUE_STATIC_VAR 1 24 #define BOOST_HOF_HAS_UNIQUE_STATIC_LAMBDA_FUNCTION_ADDR 1 25 #endif 26 27 namespace fit_test { 28 29 BOOST_HOF_STATIC_LAMBDA_FUNCTION(fit_sum_lambda) = [](int x, int y) __anona7c5c53d0102(int x, int y) 30{ 31 return x + y; 32 }; 33 34 struct fit_sum_f 35 { operator ()fit_test::fit_sum_f36 constexpr int operator()(int x, int y) const 37 { 38 return x + y; 39 } 40 }; 41 42 BOOST_HOF_STATIC_LAMBDA_FUNCTION(fit_sum_fo) = fit_sum_f(); 43 44 BOOST_HOF_STATIC_FUNCTION(fit_sum_constexpr_fo) = fit_sum_f(); 45 46 BOOST_HOF_DECLARE_STATIC_VAR(fit_sum_var, fit_sum_f); 47 48 // BOOST_HOF_STATIC_FUNCTION(fit_sum) = [](auto x, auto y) 49 // { 50 // return x + y; 51 // }; 52 53 template<class T> fit_sum(T x,T y)54T fit_sum(T x, T y) 55 { 56 return x + y; 57 }; 58 59 } 60 61 #endif 62