C
Chris Thomasson
I was thinking of how I was going to create a robust versioning system in
Standard C++ for my library and was wondering exactly what the point of a
namespace alias is? The seem like a rather limited approach. For instance,
you simply cannot "add-on" to a aliased namespace... Here is a quick example
of what I am talking about:
__________________________
#include <stdio.h>
// version 1 of my library
namespace mylib_version_1 {
namespace constant {
char const name[] = "My Library Version 1.0";
}
}
// version 1 of my library
namespace mylib_version_2 {
namespace constant {
char const name[] = "My Library Version 2.0";
}
}
// method 1: create namespace alias to version 1
namespace mylib_alias = mylib_version_1;
// method 2: create namespace using version 2
namespace mylib_using {
using namespace mylib_version_2;
}
// can't add to namespace mylib_alias!!
// uncomment for error!
// why can't you do this???
/*
namespace mylib_alias {
class something_extra {
};
}
*/
// add to namespace mylib_using
namespace mylib_using {
class something_extra {
};
}
// entry
int main() {
printf("method 1: %s\n", mylib_alias::constant::name);
printf("method 2: %s\n", mylib_using::constant::name);
return 0;
}
_______________________
Anybody making good use out of namespace aliases? I can't think of why I
would choose to use 'method 1' over 'method 2' in the implementation of my
versioning system. Especially when you can't add to a namespace alias
created with 'method 1'! I know I must be missing something here... Humm...
Standard C++ for my library and was wondering exactly what the point of a
namespace alias is? The seem like a rather limited approach. For instance,
you simply cannot "add-on" to a aliased namespace... Here is a quick example
of what I am talking about:
__________________________
#include <stdio.h>
// version 1 of my library
namespace mylib_version_1 {
namespace constant {
char const name[] = "My Library Version 1.0";
}
}
// version 1 of my library
namespace mylib_version_2 {
namespace constant {
char const name[] = "My Library Version 2.0";
}
}
// method 1: create namespace alias to version 1
namespace mylib_alias = mylib_version_1;
// method 2: create namespace using version 2
namespace mylib_using {
using namespace mylib_version_2;
}
// can't add to namespace mylib_alias!!
// uncomment for error!
// why can't you do this???
/*
namespace mylib_alias {
class something_extra {
};
}
*/
// add to namespace mylib_using
namespace mylib_using {
class something_extra {
};
}
// entry
int main() {
printf("method 1: %s\n", mylib_alias::constant::name);
printf("method 2: %s\n", mylib_using::constant::name);
return 0;
}
_______________________
Anybody making good use out of namespace aliases? I can't think of why I
would choose to use 'method 1' over 'method 2' in the implementation of my
versioning system. Especially when you can't add to a namespace alias
created with 'method 1'! I know I must be missing something here... Humm...