Saturday 15 September 2012

c++ - What is the purpose of this namespace? -



c++ - What is the purpose of this namespace? -

in boost 1.55, current_function.hpp reads this:

namespace boost { namespace detail { inline void current_function_helper() { #if defined(__gnuc__) || (defined(__mwerks__) && (__mwerks__ >= 0x3000)) || (defined(__icc) && (__icc >= 600)) || defined(__ghs__) # define boost_current_function __pretty_function__ #elif ... #endif } } // namespace detail } // namespace boost

why did author bother writing namespaces?

detail namespaces help avoid polluting official ones internal functions or classes user doesn't need know of.

modern ides parse header files , provide code completion, is, suggestions names if start write boost::c. quite unusable if internal algorithms such e.g. copy_pod_nontrivial listed. moreover, typo lead phone call internal function or declaration of object of internal class type. not want.

a more technical reason adl: functions found type of arguments (template arguments function templates involved); can cause name lookup search names in official namespace. if helper functions (or classes) declared within it, may cause problems overload resolution.

users should never (need to) utilize internal functions, if see user code accesses detail-like namespace should on guard.

c++ c++11 namespaces preprocessor inline-namespaces

No comments:

Post a Comment