C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Library version control using namespace aliases

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Craig Henderson
Guest





PostPosted: Wed Mar 03, 2004 8:29 pm    Post subject: Library version control using namespace aliases Reply with quote



Does anyone have any practical experiencing of using namespace aliases to
control which version of a specific library to use at compile time? For
example, if a version 1.00 of a library was implemented within a namespace
abclib_100, and version 2.00 was within namespace abclib_200, the user could
use "using abc=abclib_100;" in their code and switch to v2.00 of the library
with a simple change.

How practical is this technique in reality, though? It assumes stability of
the interface from v1.00 to v2.00 (is that really a negative?), but it does
encourage backward compatibility in the interface design (a positive?). I
think it should be possible to use lazy instantiation and static assertions
to protect, at compile-time, against using deprecated functionality, but I'm
unconvinced that this is a good idea really.

Any thought or experience on this method would be great!

Thanks
-- Craig



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Eugene Gershnik
Guest





PostPosted: Thu Mar 04, 2004 1:04 pm    Post subject: Re: Library version control using namespace aliases Reply with quote



Craig Henderson wrote:
Quote:
Does anyone have any practical experiencing of using namespace
aliases to control which version of a specific library to use at
compile time? For example, if a version 1.00 of a library was
implemented within a namespace abclib_100, and version 2.00 was
within namespace abclib_200, the user could use "using
abc=abclib_100;" in their code and switch to v2.00 of the library
with a simple change.

How practical is this technique in reality, though?

See the thread starting with
http://groups.google.com/groups?hl=en&threadm=A62cndoMHuZUEfCjXTWc3Q%40speakeasy.net
for a reason why this may not be such a good idea.

--
Eugene




[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Allan W
Guest





PostPosted: Fri Mar 05, 2004 10:45 am    Post subject: Re: Library version control using namespace aliases Reply with quote



"Eugene Gershnik" <gershnik (AT) nospam (DOT) hotmail.com> wrote
Quote:
Craig Henderson wrote:
Does anyone have any practical experiencing of using namespace
aliases to control which version of a specific library to use at
compile time? For example, if a version 1.00 of a library was
implemented within a namespace abclib_100, and version 2.00 was
within namespace abclib_200, the user could use "using
abc=abclib_100;" in their code and switch to v2.00 of the library
with a simple change.

How practical is this technique in reality, though?

See the thread starting with
http://groups.google.com/groups?hl=en&threadm=A62cndoMHuZUEfCjXTWc3Q%40speakeasy.net
for a reason why this may not be such a good idea.

Hmmm... that thread started with someone that wanted to do a forward
declaration to a namespace-scope class.

Nobody mentioned that this would be possible, if the two different
libraries both had a nested namespace with the same name:


#include <iostream>

namespace lib_v1 {
namespace classes {}
}

namespace lib_v2 {
namespace classes {}
}

// The namespace alias
namespace lib = lib_v2;

// The forward declaration
namespace lib { // Uses the alias
namespace classes { // Uses the nested namespace
struct someclass;
}
}


// The actual declarations
namespace lib_v1 {
namespace classes {
struct someclass {
someclass()
{ std::cout << "lib_v1::classes::someclassn"; }
};
}
}
namespace lib_v2 {
namespace classes {
struct someclass {
someclass()
{ std::cout << "lib_v2::classes::someclassn"; }
};
}
}

// The test
int main() {
//lib_v1::classes::someclass sc1;
//lib_v2::classes::someclass sc2;
lib::classes::someclass sc;
std::cout << std::endl;
return 0; // To supress MSVC 6.0 warning
}

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Dietmar Kuehl
Guest





PostPosted: Fri Mar 05, 2004 2:33 pm    Post subject: Re: Library version control using namespace aliases Reply with quote

"Craig Henderson" <. (AT) eu (DOT) uu.net> wrote:
Quote:
Does anyone have any practical experiencing of using namespace aliases
to
control which version of a specific library to use at compile time?

Although I didn't try to use something like this for versioning but
rather for configuration choices (debugging vs. efficiency, no
extension, etc.) I think the experience still qualifies. My conclusion
is that the current C++ namespaces are not suitable for such a thing,
at least not for the standard C++ library. Basically, I encountered two
problems:

- Argument dependent lookup really only looks into the respective scope.
- A namespace alias cannot be used to reopen a namespace.

Effectively, the first means that the two versions of the library have
to be entirely separated: there cannot be any overlap between the
versions. You cannot use a type from version 1 in your version 2
because any namespace functions would only be sought in version 1,
missing everything in version 2 - both extensions as well as
replacements. Correspondingly, every function from version 1 has to be
replicated in version 2 if it can be used with types new in version 2.

The net effect of this is that you cannot use functions from version 1
using types from version 2 or vice versa. Effectively, this means you
cannot mix use of version 1 and version 2. Thus, what is the point of
having duplicate things in header files? Ease of configuration, as you
claim, is not really the case, IMO: you need the namespace alias in
each and every file using the library. "ell, of course, this can be
accomplished using a header file included in all files for exactly this
purpose. On the other hand, configuration choice is not necessary a
source level activity and can often be easier configured on the level
of the build-system, eg. by specifying the include search path or by
changing a symbolic link to a directory.

The second problem, reopening namespaces using namespace aliases, comes
into the picture if you allow or require overloads or specializations
to be made in your library's namespace, eg.:

namespace std {
struct iterator_traits<my_iterator> {
};
}

This use of 'std' does not work if 'std' is a namespace alias! This
effectively prohibits use of a namespace alias everywhere a user
expects a "real" namespace.

Actually, this really reduces the usefulness of namespaces by quite a
lot. Of course, the rules currently in place a quite reasonable in some
situations but unfortunately not in all. Thus, it would be desirable to
have distinctions eg. for 'using' declarations which would allow lookup
for the respective names in corresponding namespaces, too. This would
kind of address the first issue. I have, however, not yet found a good
reason why namespace aliases cannot be used to reopen a namespace.
--
<mailto:dietmar_kuehl (AT) yahoo (DOT) com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Eugene Gershnik
Guest





PostPosted: Sat Mar 06, 2004 12:02 am    Post subject: Re: Library version control using namespace aliases Reply with quote

Allan W wrote:
Quote:
namespace lib_v1 {
namespace classes {}
}

namespace lib_v2 {
namespace classes {}
}

// The namespace alias
namespace lib = lib_v2;

// The forward declaration
namespace lib { // Uses the alias

The line above is illegal I think.

--
Eugene



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.