Reading and researching a lot about the new C++11 feature - "inline namespace" I don't understand what the real benefit of this feature is.
I could easily have all the functions/types which are defined in an "inline namespace" placed directly in the enclosing one and have the same result. So what is the real motivation of placing functions/types in an inline namespace? Grouping the functions/types? Is there any ADL related benefit in using "inline namespace"? I thought ADL would behave the same was as there was an implicit "using" directive for this "inline namespace."
EDIT1:
So I think the following is the key advantage. Let's say initially we have this:
namespace toplevel {
// Users can use toplevel::MyType
inline namespace current {
class MyType {};
} // inline namespace current
} // ns toplevel
Now, some new requirements, and we need a new version to be available but keep the old one intact:
namespace toplevel {
// Users can use toplevel::MyType
// we can let the users know that we are going to deprecate it
// in favor of toplvel::next::MyType
inline namespace current {
class MyType {};
} // inline namespace current
// Users can use toplevel::next::MyType
namespace next {
class MyType {};
} // namespace next
} // ns toplevel
And finally do this. Move inline to the "next" namespace making it the default. Still letting the users access to "current" but with explicit ::current - i.e. this way: toplevel::current::MyType BTW - my preference would even rename "current" to "deprecated".
namespace toplevel {
// Users can still use it by referring
// to toplevel::current::MyType
namespace current {
class MyType {};
} // inline namespace current
// Have this one the default one
// under toplevel
// Users can use the new one this way: toplevel::MyType
inline namespace next {
class MyType {};
} // namespace next
} // ns toplevel
Does it sound like a correct scenario?