 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Craig Henderson Guest
|
Posted: Wed Mar 03, 2004 8:29 pm Post subject: Library version control using namespace aliases |
|
|
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
|
Posted: Thu Mar 04, 2004 1:04 pm Post subject: Re: Library version control using namespace aliases |
|
|
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
|
Posted: Fri Mar 05, 2004 10:45 am Post subject: Re: Library version control using namespace aliases |
|
|
"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
|
Posted: Fri Mar 05, 2004 2:33 pm Post subject: Re: Library version control using namespace aliases |
|
|
"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
|
Posted: Sat Mar 06, 2004 12:02 am Post subject: Re: Library version control using namespace aliases |
|
|
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 |
|
 |
|
|
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
|
|