diff --git a/include/boost/config/suffix.hpp b/include/boost/config/suffix.hpp index 6635666b..051dd1f1 100644 --- a/include/boost/config/suffix.hpp +++ b/include/boost/config/suffix.hpp @@ -337,6 +337,72 @@ namespace std { # define BOOST_DEDUCED_TYPENAME #endif +// BOOST_[APPEND_]TEMPLATE_EXPLICITLY_SPECIFIED_[NON_]TYPE macros -------------// +// +// Some compilers have problems with function templates whose +// template parameters don't appear in the function parameter list. +// +// Basically they just link one instantiation of the template in +// the final executable. + +// Example: +// +// #include +// #include +// +// template +// void f() { std::cout << n << '\n'; } + +// int main() { +// f<1>(); +// f<2>(); +// } +// +// OUTPUT is: +// +// 2 +// 2 +// +// Write the definition of f as +// +// template +// void f(BOOST_TEMPLATE_EXPLICITLY_SPECIFIED_NON_TYPE(int, n)) +// { std::cout << n << '\n'; } + +#if defined BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS + +# include "boost/type.hpp" +# include "boost/non_type.hpp" + +// For type parameters + +#define BOOST_TEMPLATE_EXPLICITLY_SPECIFIED_TYPE(t) \ + boost::type* = 0 +#define BOOST_APPEND_TEMPLATE_EXPLICITLY_SPECIFIED_TYPE(t) \ + , BOOST_TEMPLATE_EXPLICITLY_SPECIFIED_TYPE(t) + +// For non-type parameters +// +#define BOOST_TEMPLATE_EXPLICITLY_SPECIFIED_NON_TYPE(t, v) \ + boost::non_type* = 0 +#define BOOST_APPEND_TEMPLATE_EXPLICITLY_SPECIFIED_NON_TYPE(t, v) \ + , BOOST_TEMPLATE_EXPLICITLY_SPECIFIED_NON_TYPE(t, v) + + +#else + +// no workaround needed: expand to nothing + +#define BOOST_TEMPLATE_EXPLICITLY_SPECIFIED_TYPE(t) +#define BOOST_APPEND_TEMPLATE_EXPLICITLY_SPECIFIED_TYPE(t) + +#define BOOST_TEMPLATE_EXPLICITLY_SPECIFIED_NON_TYPE(t, v) +#define BOOST_APPEND_TEMPLATE_EXPLICITLY_SPECIFIED_NON_TYPE(t, v) + + +#endif // defined BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS + + // ---------------------------------------------------------------------------// //