-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable top-level namespace (for standalone) #769
Comments
@jzmaddock will need to sign off, but a priori I see no reason why this shouldn't be done. Have you tried the standalone? Might help to scope the problem a bit and I believe there is CMake tooling to help with this particular problem. |
Yep! We've been using it since we merged microsoft/STL#2151 in Aug 2021. |
Could this be done via |
According to my extremely vague understanding, that's already the default for MSVC, and it applies to DLLs. On the MSVC platform, we don't usually have a term for it, since one has to intentionally "dllexport" a symbol (otherwise it's what other platforms would call "hidden"). But within a static library, the concept of "dllexported vs. hidden" doesn't apply - all symbols are mixed together with no isolation. |
Seems like a perfectly reasonable request, I guess we would just have to macro-ise the namespace open and closing? |
Yes. I have done something like this in other projects. Basically, you provide a macro which can supply an outer namespace (which can also be a C++17 nested namespace). You then need to define separate The big change I found, however, was in testing. Since you will also want to test some tests with/without the outer namespace, you might end up needing to change a lot of test code to either be |
Yes, that's what I had in mind. My precise use case could be addressed by using a macro for the top-level namespace name ( One design choice to be made is whether the open/close macros include the inner-most braces or not. In other words, do you want: BOOST_MATH_BEGIN // default definition "namespace boost {"
template <class T> class potato;
BOOST_MATH_END // default definition "}"
namespace std {
template <class T>
struct numeric_limits<BOOST_MATH_PATH::potato<T>> { /* ... */ }; // default definition "::boost"
} or BOOST_MATH_BEGIN { // default definition "namespace boost"
template <class T> class potato;
} BOOST_MATH_END // default definition ""
namespace std {
template <class T>
struct numeric_limits<BOOST_MATH_PATH::potato<T>> { /* ... */ }; // default definition "::boost"
} I believe the former is more common, but the latter is nice for those of us who like to format with indents in namespaces =) |
I would tend to weakly prefer the latter. |
Hi @jzmaddock I would like to start giving this one a try. I can maybe handle it. But we need to decide a few things.
This is how I have done this kind of think in the past for some of my own header-only libraries. So then if the client defines #define BOOST_MATH_OUTER_NAMESPACE=my_stl_specfun then the real namespace for Cc: @CaseyCarter and @mborland and @NAThompson |
I had assumed (perhaps incorrectly) that we would maybe use something like:
|
You would have to only define thos if they were undefined, thus giving the client a chance to define them upstream? I don't really like it because then the entire identity of |
But (thinking out loud) would a prepended namespace give the client the desired isolation? |
I think it would isolate beacuse you're basically saying, OK |
Do we need to do anything particular in order to ensure that Multiprecision functions can still be found via ADL? |
I assume that anything that changes the name mangling would work equally well.
As long as the namespace is boost::math in the normal case I don't see we need to worry about this? |
Will it be sufficient to just replace the I'm trying to resolve this in Boost.Math by adding the #ifndef BOOST_MATH_NAMESPACE
#define BOOST_MATH_NAMESPACE math
#endif and then replace every occurrence of With the changes above, MSVC STL's But the changes need to touch 500+ files in Boost.Math and make maintenance a bit harder (every namespace |
Assuming every symbol defined by the library is currently in Purely aesthetically, I would rather write |
I prefer an outer namespace and have had good results in other projects (non-boost) with that philosophy. Also these other projects heavily use ADL. So I'd go with the outer namespace |
Personally, I would make BOOST_MATH_NAMESPACE equivalent to I have no great objection to the changes required, but it does increase the number of configurations we need to test quite a bit. |
As you probably already know, MSVC uses Boost Math to implement the C++17 mathematical special functions. (My gratitude and joy over this fact cannot be expressed with words - I did not want to spend a year of my life becoming expert enough in numerical analysis to implement these properly myself!) We have a thin wrapper layer that adapts the Standard's API to Boost's, which works great when folks link to the STL dynamically. We do have an issue, however, in that symbols in namespace
::boost
are directly visible in our static libraries, causing ODR problems for folks who are using different versions of Boost Math than we ship.Would you be amenable to a PR that made the top-level namespace configurable if we were to implement such a feature? We could maintain a fork, of course, but (1) it seems like this might be useful for other folks that want to ship third-party libs using Boost Math, and (2) we like to keep the STL's list of dependencies short and clean to make it easier to onboard new contributors.
The text was updated successfully, but these errors were encountered: